Consulting

Results 1 to 4 of 4

Thread: Hiding Cols With VBA

  1. #1
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location

    Hiding Cols With VBA

    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?
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    It shouldn't happen if you don't select the column but just hide it.
    Be as you wish to seem

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Quote Originally Posted by Aflatoon View Post
    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.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    @p45cal

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •