I'm relatively new to VBA but was "recruited" by my company to help make a resource forecasting tool. I'm getting a 6 second delay from the time that I run my script to the point where it completes and I'd really like to take that down to 1 or 2 seconds if possible.
As a side note, I probably have an absurd number of "IF's", "Index/Match's", and "Indirect's" in my excel sheet, all running across a week-ending date from column K to column EY... I'm not sure if that's my problem or if it's in my code.
as an FYI, here is an example of one of the excel formulas - if it seems overloaded and I should change it feel free to let me know
=IF(INDEX(INDIRECT("$A$3:$M$"&$K$4)),MATCH($B26,INDIRECT("$K$3:$K$"&$K$4)),0),COLUMN(F26))<40000,"InputDate",INDEX(INDIRECT("$A$3:$M$"&$K$4),MATCH($B26,INDIRECT("$K$3:$K$"&$K$4)),0),COLUMN(F26))))
Here is my VBA Code working in 3 steps.
Marco4() - Inserting rows in a project description table,
CopyM() - Creates a string from the project table (Client Name, Proj #, Project name)
Project Summary() - Copy the last range of 7 rows and then insert them 1 row below the last row.
Sub NewProject()
Macro4
CopyM
ProjectSummary
End Sub
----------------------------------------------------------
Sub Macro4()
'insert a new line in the project description field (top)
Range("A1").End(xlDown).End(xlDown).Offset(1).EntireRow.Insert Shift:=xlDown,
CopyOrigin:=xlFormatFromLeftOrAbove
Range("G3").Copy Destination:=Range("H1").End(xlDown).End(xlDown)
End Sub
-----------------------------------------------------------
Sub CopyM()
'Copy range of cells in column K which correspond only to project description field
Dim rng As Range
Dim rng2 As Range
Set rng = ActiveSheet.Range("K1").End(xlDown).End(xlDown)
Set rng2 = rng.Offset(1)
rng.Copy Destination:=rng2
Application.CutCopyMode = False
End Sub
------------------------------------------------------------
Sub ProjectSummary()
Dim lastrowe As Integer
Dim lastrowb As Integer
Dim pnext As Integer
lastrowe = Range("D2000").End(xlUp).Offset(2).Row
lastrowb = Range("A2000").End(xlUp).Offset(-1).Row
Rows(lastrowb & ":" & lastrowe).Copy
pnext = Range("D2000").End(xlUp).Offset(3).Row
Rows(pnext).Insert Shift:=xlDown
End Sub