Is there a way to speed up this looped code
Hi all,
I have some code below that I am using to hide rows other than those with a specified value generated from a userform. The loop is super slow (took almost 30 minutes last night) and I am wondering how I can speed up the process. There won’t be 20k+ populated rows but the populated rows will grow over time. I am using such a large number to get more longevity out of the spreadsheet but in reality there may not be much more that 1 – 2k a year but even that will still take time to go through the loop.
I can build in something for users to purge resolved items but the # of populated rows, that aren’t resolved will still grow over time so I need to find a faster way of hiding unpopulated rows if possible.
I don’t want to use row filters because the worksheet is protected and I also need users to go through userforms to navigate the spreadsheet.
Any assistance would be appreciated.
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
‘ Set the worksheet
Set ws = ThisWorkbook.Sheets(“MAIN”)
‘ Set the range to the data range in Column H (adjust as needed)
Set rng = ws.Range(“R6:R20005”)
‘ Loop through each cell in the specified range
For Each cell In rng
If cell.Value <> CDate(courtdate) Then
‘ Toggle the row visibility
cell.EntireRow.Hidden = Not cell.EntireRow.Hidden
End If
Next cell
Hi all, I have some code below that I am using to hide rows other than those with a specified value generated from a userform. The loop is super slow (took almost 30 minutes last night) and I am wondering how I can speed up the process. There won’t be 20k+ populated rows but the populated rows will grow over time. I am using such a large number to get more longevity out of the spreadsheet but in reality there may not be much more that 1 – 2k a year but even that will still take time to go through the loop. I can build in something for users to purge resolved items but the # of populated rows, that aren’t resolved will still grow over time so I need to find a faster way of hiding unpopulated rows if possible. I don’t want to use row filters because the worksheet is protected and I also need users to go through userforms to navigate the spreadsheet. Any assistance would be appreciated. Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
‘ Set the worksheet
Set ws = ThisWorkbook.Sheets(“MAIN”)
‘ Set the range to the data range in Column H (adjust as needed)
Set rng = ws.Range(“R6:R20005”)
‘ Loop through each cell in the specified range
For Each cell In rng
If cell.Value <> CDate(courtdate) Then
‘ Toggle the row visibility
cell.EntireRow.Hidden = Not cell.EntireRow.Hidden
End If
Next cell Read More