[FONT="]First of all I would like to thank you for taking your time to read my post, and preferably providing me with a solution to my problem, any input or assistance will be greatly appreciated. [/FONT]
I have read several posts about the importance of minimizing traffic between VBA and excel, the importance of avoiding any unnecessary reference to a worksheet once the macro has begun, the importance of a[FONT="]voiding reading or writing worksheet data within loops whenever possible, [/FONT]and reading and writing blocks of data in a single operation to speed up my code, but I have been unsuccessful at implementing any of these ideas.
Below is what I have so far, the code works but it seems to take forever to complete the task at hand, forever being 5 seconds or so.
Cell "AU6015" is the sum of all values in column "AU", this macro is triggered whenever the value of cell "AU6015" changes.
If the value of cell "AU1" is equal to 0 (zero) then row 1 is hidden, if cell "AU1" is not equal to 0 (zero) then row 1 is not hidden, the same holds true for rows 2 through 6015.
Private Sub Worksheet_Calculate()
Static oldval
If Range("AU6015").Value <> oldval Then
oldval = Range("AU6015").Value
screenUpdateState = Application.ScreenUpdating
statusBarState = Application.DisplayStatusBar
calcState = Application.Calculation
eventsState = Application.EnableEvents
displayPageBreakState = ActiveSheet.DisplayPageBreaks
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Dim i As Long
For i = 1 To 6014 Step 1
Rows(i).EntireRow.Hidden = (Range("AU" & i).Value = 0)
Next
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
End If
End Sub
[FONT="]
[/FONT]
I have read several posts about the importance of minimizing traffic between VBA and excel, the importance of avoiding any unnecessary reference to a worksheet once the macro has begun, the importance of a[FONT="]voiding reading or writing worksheet data within loops whenever possible, [/FONT]and reading and writing blocks of data in a single operation to speed up my code, but I have been unsuccessful at implementing any of these ideas.
Below is what I have so far, the code works but it seems to take forever to complete the task at hand, forever being 5 seconds or so.
Cell "AU6015" is the sum of all values in column "AU", this macro is triggered whenever the value of cell "AU6015" changes.
If the value of cell "AU1" is equal to 0 (zero) then row 1 is hidden, if cell "AU1" is not equal to 0 (zero) then row 1 is not hidden, the same holds true for rows 2 through 6015.
Private Sub Worksheet_Calculate()
Static oldval
If Range("AU6015").Value <> oldval Then
oldval = Range("AU6015").Value
screenUpdateState = Application.ScreenUpdating
statusBarState = Application.DisplayStatusBar
calcState = Application.Calculation
eventsState = Application.EnableEvents
displayPageBreakState = ActiveSheet.DisplayPageBreaks
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Dim i As Long
For i = 1 To 6014 Step 1
Rows(i).EntireRow.Hidden = (Range("AU" & i).Value = 0)
Next
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
End If
End Sub
[FONT="]
[/FONT]