Looking for VBA which would hide columns other than a list I specify
e.g. if columns are not A, D, M, CX then hide
Looking for VBA which would hide columns other than a list I specify
e.g. if columns are not A, D, M, CX then hide
Assuming you have headers in row 1, try:
Sub HideCols()
Application.ScreenUpdating = False
Dim colStr As String, lCol As Long, i As Long, x As Long, ColLetter As String
lCol = Cells(1, Columns.Count).End(xlToLeft).Column
colStr = "A, D, M,CX"
For x = 1 To lCol
ColLetter = Replace(Cells(1, x).Address(False, False), "1", "")
If InStr(colStr, ColLetter) = 0 Then
Columns(x).Hidden = True
End If
Next x
Application.ScreenUpdating = True
End Sub
Display More
Don’t have an account yet? Register yourself now and be a part of our community!