I am using a drop down list in Excel in which user select a text and then columns and/or rows are being hidden. The data that I am using is large, approx. 39K rows. I think that because of this, when "Streamline" is selected, the columns are being hidden and so are rows, but it takes an extremely long time for all the rows to hide. What I am trying to achieve is that when user selects "Streamline" then certain columns are hidden in addition to rows that do not contain "AP" in column 'R'.
So my question is: Is there a way to optimize the hiding of rows when user selects "Streamline" other than what I have done? Is there a better way?
This is the part of my code that I am questioning:
Here is the entirety of what I have in VBA thus far:
So my question is: Is there a way to optimize the hiding of rows when user selects "Streamline" other than what I have done? Is there a better way?
This is the part of my code that I am questioning:
VBA Code:
ElseIf Target.Text = "STREAMLINE" Then
Range("A:DD").EntireColumn.Hidden = False
Range("AA:AM").EntireColumn.Hidden = True
For Each cell In ActiveWorkbook.ActiveSheet.Columns("R").Cells
If cell.Value <> "AP" Then
cell.EntireRow.Hidden = True
End If
Next cell
Here is the entirety of what I have in VBA thus far:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = ("$D$1") Then
If Target.Text = "ALL" Then
Range("A:DD").EntireColumn.Hidden = False
ElseIf Target.Text = "OVERRIDES" Then
Range("A:DD").EntireColumn.Hidden = False
Range("A:C,J:L,N:O,AH:AQ,AX:AY,BF:BH,BJ:BK,BP:BQ,BT:BT,BW:BZ,CA:CB,CC:CI,CK:CK,CT:DD").EntireColumn.Hidden = True
ElseIf Target.Text = "RATES" Then
Range("A:DD").EntireColumn.Hidden = False
Range("J:K,N:O,P:P,AR:AW,BE:BF,CK:CN,CR:CS").EntireColumn.Hidden = True
ElseIf Target.Text = "STREAMLINE" Then
Range("A:DD").EntireColumn.Hidden = False
Range("AA:AM").EntireColumn.Hidden = True
For Each cell In ActiveWorkbook.ActiveSheet.Columns("R").Cells
If cell.Value <> "AP" Then
cell.EntireRow.Hidden = True
End If
Next cell
End If
End If
End Sub
Last edited by a moderator: