I have assigned VBA macro to button in excel, but they do not work.
The code does work in isolation, and when stepped though without error.
I am at a loss what to do…
All advice welcome..
Thanks
Luke
Option Explicit
Dim iColumn As Long
Dim lastColumn As Long
Dim i As Long
Dim hdr As String
Dim columnsToHide() As Variant
Sub HideSpecificColumnsCAM()
Call UnhideAllColumns
columnsToHide = Array("Part Number", "Description")
lastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
For iColumn = 1 To lastColumn
For i = LBound(columnsToHide) To UBound(columnsToHide)
hdr = columnsToHide(i)
If Cells(1, iColumn) = hdr Then
Cells(1, iColumn).EntireColumn.Hidden = True
Exit For
End If
Next i
Next iColumn
End Sub
Sub UnhideAllColumns()
Dim col As Range
Dim colrange As Range
lastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
For iColumn = 1 To lastColumn
Set colrange = WIP.Columns(iColumn)
colrange.EntireColumn.Hidden = False
Next iColumn
End Sub
Tested the code by stepping through, all seems fine, but when the macro is activated from within excel nothing seems to happen.
New contributor
Luke Kirby is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.