Hide columns using VBA in Excel
Hiding one or more columns on a worksheet
Hiding a column can be simple. Below code hides column C on the active worksheet. If you set the property Hidden
to False
the column becomes visible again.
Columns("D").Hidden = True
Below code hides multiple columns (D. E and F).
Columns("D:F").Hidden = True
Hiding columns in a range

When starting with a range which is not a complete column you will get run-time error '1004': Unable to set the Hidden property of the Range class.
Dim rng As Range: Set rng = Application.Range("B2")
rng.Hidden = True
You can fix this by applying EntireColumn to the range:
Dim rng As Range: Set rng = Application.Range("B2")
rng.EntireColumn.Hidden = True
Make a column xlVeryHidden
xlVeryHidden is not supported for Columns. A workaround is to hide it and then protect the sheet.