Hello!
I am new to VBA and trying to speed up what I already have written. Almost all of my code is written with IF statements (around 2500 lines) and the process is beginning to slow. I have provided one IF section below and was hoping someone could provide suggestions for optimizing this that I could intuitively apply to all of my code.
Thanks in advance!
Zac
I am new to VBA and trying to speed up what I already have written. Almost all of my code is written with IF statements (around 2500 lines) and the process is beginning to slow. I have provided one IF section below and was hoping someone could provide suggestions for optimizing this that I could intuitively apply to all of my code.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
'Hide/Unhide Columns for POP 6 Mo, 12 Mo, 18 Mo
If Target = Range("H14") Then
If Range("H14").Value = "6" Then
Sheet2.Columns("E:Q").EntireColumn.Hidden = False
Sheet2.Columns("R:AO").EntireColumn.Hidden = True
Sheet3.Columns("E:Q").EntireColumn.Hidden = False
Sheet3.Columns("R:AO").EntireColumn.Hidden = True
Sheet4.Columns("E:Q").EntireColumn.Hidden = False
Sheet4.Columns("R:AO").EntireColumn.Hidden = True
Sheet9.Columns("E:Q").EntireColumn.Hidden = False
Sheet9.Columns("R:AO").EntireColumn.Hidden = True
Sheet10.Columns("E:Q").EntireColumn.Hidden = False
Sheet10.Columns("R:AO").EntireColumn.Hidden = True
Sheet11.Columns("E:Q").EntireColumn.Hidden = False
Sheet11.Columns("R:AO").EntireColumn.Hidden = True
Sheet12.Columns("E:Q").EntireColumn.Hidden = False
Sheet12.Columns("R:AO").EntireColumn.Hidden = True
Sheet13.Columns("E:Q").EntireColumn.Hidden = False
Sheet13.Columns("R:AO").EntireColumn.Hidden = True
Sheet14.Columns("E:Q").EntireColumn.Hidden = False
Sheet14.Columns("R:AO").EntireColumn.Hidden = True
Sheet15.Columns("E:Q").EntireColumn.Hidden = False
Sheet15.Columns("R:AO").EntireColumn.Hidden = True
Sheet16.Columns("E:Q").EntireColumn.Hidden = False
Sheet16.Columns("R:AO").EntireColumn.Hidden = True
Sheet17.Columns("E:Q").EntireColumn.Hidden = False
Sheet17.Columns("R:AO").EntireColumn.Hidden = True
Sheet18.Columns("E:Q").EntireColumn.Hidden = False
Sheet18.Columns("R:AO").EntireColumn.Hidden = True
Sheet19.Columns("E:Q").EntireColumn.Hidden = False
Sheet19.Columns("R:AO").EntireColumn.Hidden = True
Sheet20.Columns("E:Q").EntireColumn.Hidden = False
Sheet20.Columns("R:AO").EntireColumn.Hidden = True
Sheet21.Columns("E:Q").EntireColumn.Hidden = False
Sheet21.Columns("R:AO").EntireColumn.Hidden = True
Sheet22.Columns("E:Q").EntireColumn.Hidden = False
Sheet22.Columns("R:AO").EntireColumn.Hidden = True
Sheet23.Columns("E:Q").EntireColumn.Hidden = False
Sheet23.Columns("R:AO").EntireColumn.Hidden = True
Sheet24.Columns("E:Q").EntireColumn.Hidden = False
Sheet24.Columns("R:AO").EntireColumn.Hidden = True
Sheet25.Columns("E:Q").EntireColumn.Hidden = False
Sheet25.Columns("R:AO").EntireColumn.Hidden = True
Sheet26.Columns("E:Q").EntireColumn.Hidden = False
Sheet26.Columns("R:AO").EntireColumn.Hidden = True
Sheet28.Columns("E:Q").EntireColumn.Hidden = False
Sheet28.Columns("R:AO").EntireColumn.Hidden = True
Sheet29.Columns("E:Q").EntireColumn.Hidden = False
Sheet29.Columns("R:AO").EntireColumn.Hidden = True
Sheet30.Columns("E:Q").EntireColumn.Hidden = False
Sheet30.Columns("R:AO").EntireColumn.Hidden = True
Sheet31.Columns("E:Q").EntireColumn.Hidden = False
Sheet31.Columns("R:AO").EntireColumn.Hidden = True
Sheet32.Columns("E:Q").EntireColumn.Hidden = False
Sheet32.Columns("R:AO").EntireColumn.Hidden = True
Sheet33.Columns("E:Q").EntireColumn.Hidden = False
Sheet33.Columns("R:AO").EntireColumn.Hidden = True
Sheet34.Columns("E:Q").EntireColumn.Hidden = False
Sheet34.Columns("R:AO").EntireColumn.Hidden = True
Sheet35.Columns("E:Q").EntireColumn.Hidden = False
Sheet35.Columns("R:AO").EntireColumn.Hidden = True
Sheet36.Columns("E:Q").EntireColumn.Hidden = False
Sheet36.Columns("R:AO").EntireColumn.Hidden = True
Sheet37.Columns("E:Q").EntireColumn.Hidden = False
Sheet37.Columns("R:AO").EntireColumn.Hidden = True
Sheet38.Columns("E:Q").EntireColumn.Hidden = False
Sheet38.Columns("R:AO").EntireColumn.Hidden = True
Sheet40.Columns("E:Q").EntireColumn.Hidden = False
Sheet40.Columns("R:AO").EntireColumn.Hidden = True
Sheet41.Columns("E:Q").EntireColumn.Hidden = False
Sheet41.Columns("R:AO").EntireColumn.Hidden = True
Sheet42.Columns("E:Q").EntireColumn.Hidden = False
Sheet42.Columns("R:AO").EntireColumn.Hidden = True
Sheet43.Columns("E:Q").EntireColumn.Hidden = False
Sheet43.Columns("R:AO").EntireColumn.Hidden = True
Sheet44.Columns("E:Q").EntireColumn.Hidden = False
Sheet44.Columns("R:AO").EntireColumn.Hidden = True
Sheet45.Columns("E:Q").EntireColumn.Hidden = False
Sheet45.Columns("R:AO").EntireColumn.Hidden = True
Sheet46.Columns("E:Q").EntireColumn.Hidden = False
Sheet46.Columns("R:AO").EntireColumn.Hidden = True
Sheet47.Columns("E:Q").EntireColumn.Hidden = False
Sheet47.Columns("R:AO").EntireColumn.Hidden = True
Sheet48.Columns("E:Q").EntireColumn.Hidden = False
Sheet48.Columns("R:AO").EntireColumn.Hidden = True
Sheet27.Rows("6:19").EntireRow.Hidden = False
Sheet27.Rows("20:43").EntireRow.Hidden = True
Sheet5.Rows("22:27").EntireRow.Hidden = True
Sheet7.Columns("D:Q").EntireColumn.Hidden = False
Sheet7.Columns("R:AN").EntireColumn.Hidden = True
ElseIf Range("H14").Value = "12" Then
Sheet2.Columns("E:AC").EntireColumn.Hidden = False
Sheet2.Columns("AD:AO").EntireColumn.Hidden = True
Sheet3.Columns("E:AC").EntireColumn.Hidden = False
Sheet3.Columns("AD:AO").EntireColumn.Hidden = True
Sheet4.Columns("E:AC").EntireColumn.Hidden = False
Sheet4.Columns("AD:AO").EntireColumn.Hidden = True
Sheet9.Columns("E:AC").EntireColumn.Hidden = False
Sheet9.Columns("AD:AO").EntireColumn.Hidden = True
Sheet10.Columns("E:AC").EntireColumn.Hidden = False
Sheet10.Columns("AD:AO").EntireColumn.Hidden = True
Sheet11.Columns("E:AC").EntireColumn.Hidden = False
Sheet11.Columns("AD:AO").EntireColumn.Hidden = True
Sheet12.Columns("E:AC").EntireColumn.Hidden = False
Sheet12.Columns("AD:AO").EntireColumn.Hidden = True
Sheet13.Columns("E:AC").EntireColumn.Hidden = False
Sheet13.Columns("AD:AO").EntireColumn.Hidden = True
Sheet14.Columns("E:AC").EntireColumn.Hidden = False
Sheet14.Columns("AD:AO").EntireColumn.Hidden = True
Sheet15.Columns("E:AC").EntireColumn.Hidden = False
Sheet15.Columns("AD:AO").EntireColumn.Hidden = True
Sheet16.Columns("E:AC").EntireColumn.Hidden = False
Sheet16.Columns("AD:AO").EntireColumn.Hidden = True
Sheet17.Columns("E:AC").EntireColumn.Hidden = False
Sheet17.Columns("AD:AO").EntireColumn.Hidden = True
Sheet18.Columns("E:AC").EntireColumn.Hidden = False
Sheet18.Columns("AD:AO").EntireColumn.Hidden = True
Sheet19.Columns("E:AC").EntireColumn.Hidden = False
Sheet19.Columns("AD:AO").EntireColumn.Hidden = True
Sheet20.Columns("E:AC").EntireColumn.Hidden = False
Sheet20.Columns("AD:AO").EntireColumn.Hidden = True
Sheet21.Columns("E:AC").EntireColumn.Hidden = False
Sheet21.Columns("AD:AO").EntireColumn.Hidden = True
Sheet22.Columns("E:AC").EntireColumn.Hidden = False
Sheet22.Columns("AD:AO").EntireColumn.Hidden = True
Sheet23.Columns("E:AC").EntireColumn.Hidden = False
Sheet23.Columns("AD:AO").EntireColumn.Hidden = True
Sheet24.Columns("E:AC").EntireColumn.Hidden = False
Sheet24.Columns("AD:AO").EntireColumn.Hidden = True
Sheet25.Columns("E:AC").EntireColumn.Hidden = False
Sheet25.Columns("AD:AO").EntireColumn.Hidden = True
Sheet26.Columns("E:AC").EntireColumn.Hidden = False
Sheet26.Columns("AD:AO").EntireColumn.Hidden = True
Sheet28.Columns("E:AC").EntireColumn.Hidden = False
Sheet28.Columns("AD:AO").EntireColumn.Hidden = True
Sheet29.Columns("E:AC").EntireColumn.Hidden = False
Sheet29.Columns("AD:AO").EntireColumn.Hidden = True
Sheet30.Columns("E:AC").EntireColumn.Hidden = False
Sheet30.Columns("AD:AO").EntireColumn.Hidden = True
Sheet31.Columns("E:AC").EntireColumn.Hidden = False
Sheet31.Columns("AD:AO").EntireColumn.Hidden = True
Sheet32.Columns("E:AC").EntireColumn.Hidden = False
Sheet32.Columns("AD:AO").EntireColumn.Hidden = True
Sheet33.Columns("E:AC").EntireColumn.Hidden = False
Sheet33.Columns("AD:AO").EntireColumn.Hidden = True
Sheet34.Columns("E:AC").EntireColumn.Hidden = False
Sheet34.Columns("AD:AO").EntireColumn.Hidden = True
Sheet35.Columns("E:AC").EntireColumn.Hidden = False
Sheet35.Columns("AD:AO").EntireColumn.Hidden = True
Sheet36.Columns("E:AC").EntireColumn.Hidden = False
Sheet36.Columns("AD:AO").EntireColumn.Hidden = True
Sheet37.Columns("E:AC").EntireColumn.Hidden = False
Sheet37.Columns("AD:AO").EntireColumn.Hidden = True
Sheet38.Columns("E:AC").EntireColumn.Hidden = False
Sheet38.Columns("AD:AO").EntireColumn.Hidden = True
Sheet40.Columns("E:AC").EntireColumn.Hidden = False
Sheet40.Columns("AD:AO").EntireColumn.Hidden = True
Sheet41.Columns("E:AC").EntireColumn.Hidden = False
Sheet41.Columns("AD:AO").EntireColumn.Hidden = True
Sheet42.Columns("E:AC").EntireColumn.Hidden = False
Sheet42.Columns("AD:AO").EntireColumn.Hidden = True
Sheet43.Columns("E:AC").EntireColumn.Hidden = False
Sheet43.Columns("AD:AO").EntireColumn.Hidden = True
Sheet44.Columns("E:AC").EntireColumn.Hidden = False
Sheet44.Columns("AD:AO").EntireColumn.Hidden = True
Sheet45.Columns("E:AC").EntireColumn.Hidden = False
Sheet45.Columns("AD:AO").EntireColumn.Hidden = True
Sheet46.Columns("E:AC").EntireColumn.Hidden = False
Sheet46.Columns("AD:AO").EntireColumn.Hidden = True
Sheet47.Columns("E:AC").EntireColumn.Hidden = False
Sheet47.Columns("AD:AO").EntireColumn.Hidden = True
Sheet48.Columns("E:AC").EntireColumn.Hidden = False
Sheet48.Columns("AD:AO").EntireColumn.Hidden = True
Sheet27.Rows("6:31").EntireRow.Hidden = False
Sheet27.Rows("32:43").EntireRow.Hidden = True
Sheet5.Rows("22:27").EntireRow.Hidden = True
Sheet7.Columns("D:AC").EntireColumn.Hidden = False
Sheet7.Columns("AB:AN").EntireColumn.Hidden = True
ElseIf Range("H14").Value = "18" Then
Sheet2.Columns("E:AO").EntireColumn.Hidden = False
Sheet3.Columns("E:AO").EntireColumn.Hidden = False
Sheet4.Columns("E:AO").EntireColumn.Hidden = False
Sheet9.Columns("E:AO").EntireColumn.Hidden = False
Sheet10.Columns("E:AO").EntireColumn.Hidden = False
Sheet11.Columns("E:AO").EntireColumn.Hidden = False
Sheet12.Columns("E:AO").EntireColumn.Hidden = False
Sheet13.Columns("E:AO").EntireColumn.Hidden = False
Sheet14.Columns("E:AO").EntireColumn.Hidden = False
Sheet15.Columns("E:AO").EntireColumn.Hidden = False
Sheet16.Columns("E:AO").EntireColumn.Hidden = False
Sheet17.Columns("E:AO").EntireColumn.Hidden = False
Sheet18.Columns("E:AO").EntireColumn.Hidden = False
Sheet19.Columns("E:AO").EntireColumn.Hidden = False
Sheet20.Columns("E:AO").EntireColumn.Hidden = False
Sheet21.Columns("E:AO").EntireColumn.Hidden = False
Sheet22.Columns("E:AO").EntireColumn.Hidden = False
Sheet23.Columns("E:AO").EntireColumn.Hidden = False
Sheet24.Columns("E:AO").EntireColumn.Hidden = False
Sheet25.Columns("E:AO").EntireColumn.Hidden = False
Sheet26.Columns("E:AO").EntireColumn.Hidden = False
Sheet28.Columns("E:AO").EntireColumn.Hidden = False
Sheet29.Columns("E:AO").EntireColumn.Hidden = False
Sheet30.Columns("E:AO").EntireColumn.Hidden = False
Sheet31.Columns("E:AO").EntireColumn.Hidden = False
Sheet32.Columns("E:AO").EntireColumn.Hidden = False
Sheet33.Columns("E:AO").EntireColumn.Hidden = False
Sheet34.Columns("E:AO").EntireColumn.Hidden = False
Sheet35.Columns("E:AO").EntireColumn.Hidden = False
Sheet36.Columns("E:AO").EntireColumn.Hidden = False
Sheet37.Columns("E:AO").EntireColumn.Hidden = False
Sheet38.Columns("E:AO").EntireColumn.Hidden = False
Sheet40.Columns("E:AO").EntireColumn.Hidden = False
Sheet41.Columns("E:AO").EntireColumn.Hidden = False
Sheet42.Columns("E:AO").EntireColumn.Hidden = False
Sheet43.Columns("E:AO").EntireColumn.Hidden = False
Sheet44.Columns("E:AO").EntireColumn.Hidden = False
Sheet45.Columns("E:AO").EntireColumn.Hidden = False
Sheet46.Columns("E:AO").EntireColumn.Hidden = False
Sheet47.Columns("E:AO").EntireColumn.Hidden = False
Sheet48.Columns("E:AO").EntireColumn.Hidden = False
Sheet27.Rows("6:43").EntireRow.Hidden = False
Sheet5.Rows("22:27").EntireRow.Hidden = False
Sheet7.Columns("D:AN").EntireColumn.Hidden = False
End If
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Thanks in advance!
Zac