PDA

View Full Version : Hiding Cols With VBA



MWE
03-17-2014, 04:20 PM
I am running xl2003 and WinXP. I have written tons of VBA code for xl and most other Office programs. I recently encountered a problem hiding columns under VBA control. Consider a spreadsheet with two rows of header information. Row 1 contains high level categories, row 2 contains specific headings within each category. The cells in Row 1 for a given category are merged. Assume that Category A is cols 1 through 5 so cells (1,1) to (1,5) are merged.

Under manual control, you can hide/unhide any of the cols in category A and you get what you expect, e.g., if you select col 2 and right click to hide it, col 2 is hidden while cols 1, 3, 4 and 5 remain visible. However, if you do that with VBA code, all the cols in the category with merged cells in row 1 are hidden. In the simple case, if you use VBA to hide col 2, cols 1 through 5 are hidden.

Anyone know what this happens?

Aflatoon
03-17-2014, 04:43 PM
It shouldn't happen if you don't select the column but just hide it.

p45cal
03-19-2014, 11:14 AM
It shouldn't happen if you don't select the column but just hide it.Exactly.. the likes of:
Columns("B:B").EntireColumn.Hidden = True
or:
Columns(3).EntireColumn.Hidden = True
should work.

snb
03-19-2014, 01:35 PM
@p45cal

do not exaggerate: Columns(2).Hidden = True will do. ;)