Hi and welcome to the forum,
For stuff like this I generally use a helper row (say row 1) with a formula that determines whether the column should be hidden. e.g. in A1 copied across
Then a macro like
You are picking up lots of extra columns becuase of the UsedRange property. Even when you've deleted stuff in columns or rows so that the entire column/row is blank, Excel still remembers the last column & row you used. This will persist until you save the workbook.
Incidentally there's a school of thought that says integer variables are converted to long variables by VBA so you may as well declare them as long in the first place and avoid VBA having to spend time doing it. Not that you'd notice a few extra milliseconds but if true, and I've no reason to doubt it, the idea is a sound one.
Bookmarks