jackal764u
New Member
- Joined
- Jul 15, 2019
- Messages
- 11
Hi,
I need help with a macro that works perfectly,
but when data in sheet increases to thousands of rows, it hangs (unresposive with grayed out screen).
The macro was modified/created by 'Fluff' (Thanks again!).
My additions & alterations are between "Start of My test code here" and "End of my test code"
and where referenses to Nary2 are made, also all comments are mine.
Your help is appreciated.
I need help with a macro that works perfectly,
but when data in sheet increases to thousands of rows, it hangs (unresposive with grayed out screen).
The macro was modified/created by 'Fluff' (Thanks again!).
My additions & alterations are between "Start of My test code here" and "End of my test code"
and where referenses to Nary2 are made, also all comments are mine.
Your help is appreciated.
VBA Code:
Sub AddCategories3() 'When changing cols just edit .range refs in "" commas
Application.ScreenUpdating = False
Dim Ary As Variant, Nary As Variant, Nary2 As Variant ' Nary=Cells K2 to N (MoneyData). Ary=Cells D2 to G (KW). Nary2=Cells D2 to I (MoneyData)
Dim r As Long, i As Long, j As Long
With Sheets("Keywords")
Ary = .Range("D2", .Range("G" & Rows.Count).End(xlUp)).Value2 ' Value2 Uses real values that are not formatted i.e. date format
End With
With Sheets("MoneyData")
If MsgBox("Reset IDs before running new search?", vbYesNo, "Reset") = vbYes Then .Range("K2:N" & .Rows.Count).ClearContents
Nary = .Range("I2:N" & .Range("I" & Rows.Count).End(xlUp).Row) 'All Cells from K2 to N in MoneyData
Nary2 = .Range("D2:I" & .Range("I" & Rows.Count).End(xlUp).Row) 'All Cells from D2 to I in MoneyData
End With
For r = 1 To UBound(Nary) ' Nary = "I2:N" From Memo Col in (MoneyData)
For i = 1 To UBound(Ary) ' Ary = "D2:G" From Payee Col in (KW)
If Ary(i, 4) <> "" And InStr(1, Nary(r, 1), Ary(i, 4), vbTextCompare) Then ' If Cells are not empty Then
Nary(r, 3) = Ary(i, 1) 'Nary(r, Col K) = Ary(i, Col D) Correct payee from keywords sheet used
Nary(r, 4) = Ary(i, 2) 'Nary(r, Col L) = Ary(i, Col E) Correct category from keywords sheet used
Nary(r, 5) = Ary(i, 3) 'Nary(r, Col M) = Ary(i, Col F) Correct subcategory from keywords sheet used
Nary(r, 6) = Ary(i, 4) 'Nary(r, Col N) = Ary(i, Col G) keyword used to categorize from keywords sheet
Exit For 'my optional commenting out
End If
'' Start of My test code here
For j = r To UBound(Nary2) ' Nary2 = "D2:I" Memo Col D to Col I
If Nary2(j, 6) = "" Then ' does all @ once, I need line by line
' Nary(r, 1) = "MData Memo is Empty" 'uncommented = keyword sheet, commented out = lines below, r, 1 stays empty
Nary(r, 3) = Nary2(j, 1) 'Nary(r, Col K) = Nary2(j, Col D) Correct payee from Col D
Nary(r, 4) = Nary2(j, 4) 'Nary(r, Col L) = Nary2(j, Col G) Correct category from Col G
Nary(r, 5) = Nary2(j, 5) 'Nary(r, Col M) = Nary2(j, Col H) Correct subcategory from Col H
Nary(r, 6) = Nary2(j, 6) 'Nary(r, Col N) = Nary2(j, Col I) keyword used to categorize from Col I
Exit For
End If ' if commented out, runs through entire sheet, not just empty memo rows
Next j
'' End of my test code
Next i
Next r
Sheets("MoneyData").Range("I2").Resize(UBound(Nary), 6).Value = Nary
Sheets("MoneyData").Range("D2").Resize(UBound(Nary2), 6).Value = Nary2
Application.ScreenUpdating = True
End Sub