|
-
Sep 30th, 2014, 10:23 AM
#1
Thread Starter
Lively Member
[RESOLVED] Excel VBA: Macro to hide columns not working
I have a macro which is supposed to provide a view of my database, however, when I run the macro, it will not work.
What I'm trying to get the macro to do is hide the following columns:
but when I run the macro it hides G through M, and O through Z. I have tried to break the macro down into several smaller macros and "call" them in a master macro for that series of macros, but I continue to get the same results.
Here is the master macro:
Code:
Sub View_Fiscal()
'
' Macro1 Macro
'
Application.ScreenUpdating = False
Call Unhide_Contra_Info
Call VF_1
Call VF_2
Call vf_3
Range("a1").Select
End Sub
Private Sub VF_1()
Columns("G:M").Select
Selection.EntireColumn.Hidden = True
Range("a1").Select
End Sub
Private Sub VF_2()
Columns("P:P").Select
Selection.EntireColumn.Hidden = True
Range("a1").Select
End Sub
Private Sub vf_3()
Columns("T:Z").Select
Selection.EntireColumn.Hidden = True
Range("a1").Select
End Sub
-
Sep 30th, 2014, 11:07 AM
#2
Re: Excel VBA: Macro to hide columns not working
if i comment out the call to "contra..." it does exactly what you are trying to do.
-
Sep 30th, 2014, 11:09 AM
#3
Re: Excel VBA: Macro to hide columns not working
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
-
Sep 30th, 2014, 12:12 PM
#4
Re: Excel VBA: Macro to hide columns not working
 Originally Posted by vbfbryce
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?
-
Sep 30th, 2014, 12:22 PM
#5
Re: Excel VBA: Macro to hide columns not working
I DO get paid by the line item (when doing "project management" here at work!)!
-
Sep 30th, 2014, 04:03 PM
#6
Thread Starter
Lively Member
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.
-
Nov 6th, 2016, 07:51 AM
#7
New Member
Re: [RESOLVED] Excel VBA: Macro to hide columns not working
The this useful example file for the topic can be reviewed : Excel Vba Column Hiding-Unhiding With Horizontal Form
In this template userform, module, class module was used.
Source for example file
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|