Ottsel
Board Regular
- Joined
- Jun 4, 2022
- Messages
- 177
- Office Version
- 365
- Platform
- Windows
I have this for loop that creates a workbook reference using data from columns A, B, and C. I've dimmed strings to make a structure.
Would there be a way to step away from my for loop and going into a whole column paste instead?
For example: have the macro select from row 12 down to the selected 'row' and just make all the formulas by column instead of having to loop through each and every row. This way it would only loop through columns D:K.
The reason: on my main computer this works fine, but on my other this macro takes a very long time to complete when I have over 500 rows of data to reference.
Here's my working code currently; any help, tips or advice would be greatly appreciated!
Would there be a way to step away from my for loop and going into a whole column paste instead?
For example: have the macro select from row 12 down to the selected 'row' and just make all the formulas by column instead of having to loop through each and every row. This way it would only loop through columns D:K.
The reason: on my main computer this works fine, but on my other this macro takes a very long time to complete when I have over 500 rows of data to reference.
Here's my working code currently; any help, tips or advice would be greatly appreciated!
VBA Code:
Dim r As Long 'row
Dim row As Long 'row count
Dim FormulaStart As String
Dim FormulaHook As String
Dim Address As String
Dim Ph1Num As String
Dim Ph1Hrs As String
Dim Ph2Num As String
Dim Ph2Hrs As String
Dim Ph3Num As String
Dim Ph3Hrs As String
row = Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count
FormulaStart = "='G:\JOBCARDS\"
'Builder = Range("A" & r).Value & "\"
'Tract = Range("B" & r).Value & "\[Lot"
'LotNum = Range("C" & r).Value
FormulaHook = ".xls]"
Address = "LCV'!$M$3"
Ph1Num = "JobCard'!$H$30"
Ph1Hrs = "JobCard'!$G$30"
Ph2Num = "JobCard'!$H$64"
Ph2Hrs = "JobCard'!$G$64"
Ph3Num = "JobCard'!$H$91"
Ph3Hrs = "JobCard'!$G$91"
Siding = "JobCard'!$D$70"
'...Prevent from Forumlas filling all the way down
'Application.AutoCorrect.AutoFillFormulasInLists = False
Application.DisplayAlerts = False
For r = 12 To row + 12
If Len(ActiveSheet.Range("A" & r).Value) > 0 Then
Range("D" & r).Value = FormulaStart & Range("A" & r).Value & "\" & Range("B" & r).Value & "\[Lot" & Range("C" & r).Value & FormulaHook & Address
Range("E" & r).Value = FormulaStart & Range("A" & r).Value & "\" & Range("B" & r).Value & "\[Lot" & Range("C" & r).Value & FormulaHook & Ph1Num
Range("F" & r).Value = FormulaStart & Range("A" & r).Value & "\" & Range("B" & r).Value & "\[Lot" & Range("C" & r).Value & FormulaHook & Ph1Hrs
Range("G" & r).Value = FormulaStart & Range("A" & r).Value & "\" & Range("B" & r).Value & "\[Lot" & Range("C" & r).Value & FormulaHook & Ph2Num
Range("H" & r).Value = FormulaStart & Range("A" & r).Value & "\" & Range("B" & r).Value & "\[Lot" & Range("C" & r).Value & FormulaHook & Ph2Hrs
Range("Z" & r).Value = FormulaStart & Range("A" & r).Value & "\" & Range("B" & r).Value & "\[Lot" & Range("C" & r).Value & FormulaHook & Siding
If Range("Z" & r).Value > 0 Then
Range("I" & r).Value = FormulaStart & Range("A" & r).Value & "\" & Range("B" & r).Value & "\[Lot" & Range("C" & r).Value & FormulaHook & Ph3Num
Range("J" & r).Value = FormulaStart & Range("A" & r).Value & "\" & Range("B" & r).Value & "\[Lot" & Range("C" & r).Value & FormulaHook & Ph3Hrs
Range("K" & r).Formula = "=IF(AND(E" & r & "=100%,G" & r & "=100%,I" & r & "=100%),""Done"",IF(AND(E" & r & "=100%,G" & r & "=100%,I" & r & "=""n/a""),""Done"",""""))"
Range("A" & r).Activate
Else
Range("I" & r).Value = "n/a"
Range("J" & r).Value = "n/a"
Range("K" & r).Formula = "=IF(AND(E" & r & "=100%,G" & r & "=100%,I" & r & "=100%),""Done"",IF(AND(E" & r & "=100%,G" & r & "=100%,I" & r & "=""n/a""),""Done"",""""))"
Range("A" & r).Activate
End If
End If
Next r