I'm having quite the struggle with some code that used to work just fine. In one of my subs, I hide a bunch of rows (1599 to be exact), then unhide the ones I need, usually around 200. Check out the code:
Private Sub HideUnneededRows(numberToShow As Integer)
Dim thisSheet As Worksheet
Dim allHideableRows As String, rowsToShow As String
Dim firstRow As Integer
Dim secondRow As Integer
Dim lastRow As Integer
Dim lastRowToShow As Integer
Set thisSheet = ThisWorkbook.Sheets(1)
firstRow = thisSheet.Range("mass1").row
secondRow = firstRow + 1
lastRow = firstRow - 1 + maxNumberOfRows
lastRowToShow = firstRow - 1 + numberToShow '//numberToShow is usually 200
'//THIS NEXT LINE RUNS, BUT STOPS EXECUTING AFTER THE ACTION IS PERFORMED
Range("A" + CStr(secondRow) + ":A" + CStr(lastRow)).EntireRow.Hidden = True
Range("A" + CStr(secondRow) + ":A" + CStr(lastRowToShow)).EntireRow.Hidden = False
End Sub
All is well and good until the code hides the rows (first of the "Range("A" +....).Hidden" lines). It performs the hide action just fine, but then doesn't reach the next line of code, which would be to un-hide a different set of rows. Things I've tried:
- Hard-coding the range string (i.e.
Range("A25:A1623")instead ofRange("A" + CStr(secondRow) + ":A" + ....)) - Performing these two hide actions through the
Rowsobject (i.e.Rows("25:1623").Hidden = True) - Extracting those two hide lines into their own
button_clickevent in a new module to see if it was something about the module it was currently in
All of these have yielded the exact same result - the code stops all execution after the 1599 rows are hidden.
Help?!
Volatile). Maybe try disabling events and screen updates prior to the hide (and re-enable of course). - PeterTScreenUpdatingfixed the problem. Why did that work? Why would a lot of recalculations (I did have approx 4800 cells with conditional formatting) cause the code to die? - deasa