So I have a column, say Expenses, which contains the name of an expense being claimed. I have such a list for each month, each month being a separate sheet. The goal is to get a
Excel freezes, because you are using Rows.Count
in your code. Thus, it loops up to 1048576
for every worksheet in your workbook. Try to get the last used row and to loop up to it.
This is a way to check the last used row in column F
in worksheet ws
:
lastRow (ws.Name, 6)
Function lastRow(Optional strSheet As String, Optional columnToCheck As Long = 1) As Long
Dim shSheet As Worksheet
If strSheet = vbNullString Then
Set shSheet = ActiveSheet
Else
Set shSheet = Worksheets(strSheet)
End If
lastRow = shSheet.Cells(shSheet.Rows.Count, columnToCheck).End(xlUp).Row
End Function