Ways to optimize VBA loop
I have a document with a lot of data and VLOOKUP functions that takes way to long to run loop code on. I am trying to hide a column if that column contains an X in row 3. The current code runs through each column checking for X and takes about 3 minutes to run completely. Ways to optimize or use another method to avoid the loop? I can't figure out the code to get it to select cells that have X and ignore cells that don't all at once. Here is the code I have now:
Code:
Sub HideColumns()
Dim maxCol As Integer
Dim c As Range
'Application.Calculation = xlCalculationManual
'Application.ScreenUpdating = False
maxCol = Application.CountA(ActiveSheet.Rows("3:3")) + 10
For Each c In ActiveSheet.Range("L3:" & Split(Cells(1, maxCol).Address, "$")(1) & "2").Cells
If c.Value = "X" Then
c.EntireColumn.Hidden = True
End If
Next c
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
End Sub
As you can see I have optimization code commented off.