TheWennerWoman
Active Member
- Joined
- Aug 1, 2019
- Messages
- 301
- Office Version
- 365
- Platform
- Windows
Hello, this is a small subset of the code I am using which is taking forever to loop through 74,000 records (the full code has a lot more bits to it).
How would I go about maybe reading this into an array and tghen just writing back once?
Thank you for reading.
Code:
Sub create_journal()
Dim LastRow As Long
Dim a As Long
Dim b As Long
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
b = 2
For a = 2 To LastRow
Sheet2.Range("A" & b).Value = "C5678"
Sheet2.Range("B" & b).Value = "103000"
Sheet2.Range("C" & b).Value = Range("C" & a).Value
Sheet2.Range("D" & b).Value = Range("B" & a).Value
b = b + 1
If Range("D" & a).Value <> 0 Then
Sheet2.Range("A" & b).Value = Range("A" & a).Value
Sheet2.Range("B" & b).Value = "145444"
Sheet2.Range("C" & b).Value = Range("D" & a).Value
Sheet2.Range("D" & b).Value = Range("B" & a).Value
b = b + 1
End If
If Range("E" & a).Value <> 0 Then
Sheet2.Range("A" & b).Value = Range("A" & a).Value
Sheet2.Range("B" & b).Value = "173000"
Sheet2.Range("C" & b).Value = Range("E" & a).Value
Sheet2.Range("D" & b).Value = Range("B" & a).Value
b = b + 1
End If
If Range("F" & a).Value <> 0 Then
Sheet2.Range("A" & b).Value = Range("A" & a).Value
Sheet2.Range("B" & b).Value = "199000"
Sheet2.Range("C" & b).Value = Range("F" & a).Value
Sheet2.Range("D" & b).Value = Range("B" & a).Value
b = b + 1
End If
If Range("G" & a).Value <> 0 Then
Sheet2.Range("A" & b).Value = Range("A" & a).Value
Sheet2.Range("B" & b).Value = "212000"
Sheet2.Range("C" & b).Value = Range("G" & a).Value
Sheet2.Range("D" & b).Value = Range("B" & a).Value
b = b + 1
End If
If Range("H" & a).Value <> 0 Then
Sheet2.Range("A" & b).Value = Range("A" & a).Value
Sheet2.Range("B" & b).Value = "255666"
Sheet2.Range("C" & b).Value = Range("H" & a).Value
Sheet2.Range("D" & b).Value = Range("B" & a).Value
b = b + 1
End If
Next
End Sub
How would I go about maybe reading this into an array and tghen just writing back once?
Thank you for reading.