Results 1 to 7 of 7

Thread: [RESOLVED] Excel VBA: Macro to hide columns not working

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Excel VBA: Macro to hide columns not working

    Quote Originally Posted by vbfbryce View Post
    But you don't need to select the columns first, so more like this:

    Code:
    Sub hideCols()
        Dim ws As Worksheet
        
        Set ws = ActiveSheet
        ws.Range("g1:m1").EntireColumn.Hidden = True
        ws.Range("p1").EntireColumn.Hidden = True
        ws.Range("t1:z1").EntireColumn.Hidden = True
        Set ws = Nothing
    End Sub
    Bryce you work to hard!
    Code:
     ActiveSheet.Range("g:m, p:p, t:z").EntireColumn.Hidden = True
    Or is it that you get paid by the line?

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2014
    Posts
    74

    Re: Excel VBA: Macro to hide columns not working

    Thanks guys, I'm not sure why my original code wasn't working, I thought they were doing the same thing... do you have any idea why that was?? My original code was performing an entirely different operation than what I was calling for. Maybe it was because there was no Dim'ing?

    Either way, I married the two of your codes together, ran it, and it works perfectly.

    Here's what I used:
    Code:
    Sub hidecols()
    
    Dim ws As Worksheet
    Set ws = ActiveSheet
    
        Application.ScreenUpdating = False
        
        Call Unhide_Contra_Info
            
        ActiveSheet.Range("g:m,p:p,t:z").EntireColumn.Hidden = True
            
        Range("a1").Select
    
    End Sub
    Thanks again.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width