T
Tibbs
Dear all,
I have a sheet that compares this year's sales to last year and to our
sales budget.
What I am trying to do is to hide the columns that relate to either
last year's sales or forecast, and came up with the following code. I
know almost nothing about VBA, so I contructed this by recording macros
for each stage and then editing them together. I have attached it to a
button on my worksheet.
This is my code:
Private Sub CommandButton1_Click()
' This shows the Last Year Comparison
'
'
'
Range("A:GP").Select
Selection.EntireColumn.Hidden = False
Range("A1").Select
Range("D,G:G,I:I,L:L,N:N,Q:Q,S:S,V:V,Y:Y,AB:AB,
AD:AD,AG:AG,AI:AI,AL:AL,AN:AN,AQ:AQ,AS:AS,AV:AV,
AY:AY,BB:BB,BD:BD,BG:BG,BI:BI,BL:BL,BN:BN,BQ:BQ,BS:BS,
BV:BV,BY:BY,CB:CB,CD:CD,CG:CG,CI:CI,CL:CL,CN:CN,CQ:CQ,
CS:CS,CV:CV,CY:CY,DBB,DDD,DGG,DII,DLL,DNN,
DQQ,DSS,DVV,DYY,EB:EB,ED:ED,EG:EG,EI:EI,EL:EL,
EN:EN,EQ:EQ,ES:ES,EV:EV,EY:EY,FB:FB").Select (All this is in 1 row on
my macro)
Range("D1").Activate
Selection.EntireColumn.Hidden = True
End Sub
When I run it, it comes up with the error:
Runtime Error '1004':
Method 'Range' of object '_worksheet' failed.
When I click Debug it highlights the long range.
Does anybody know what I'm doing wrong?
Many thanks
Chris
I have a sheet that compares this year's sales to last year and to our
sales budget.
What I am trying to do is to hide the columns that relate to either
last year's sales or forecast, and came up with the following code. I
know almost nothing about VBA, so I contructed this by recording macros
for each stage and then editing them together. I have attached it to a
button on my worksheet.
This is my code:
Private Sub CommandButton1_Click()
' This shows the Last Year Comparison
'
'
'
Range("A:GP").Select
Selection.EntireColumn.Hidden = False
Range("A1").Select
Range("D,G:G,I:I,L:L,N:N,Q:Q,S:S,V:V,Y:Y,AB:AB,
AD:AD,AG:AG,AI:AI,AL:AL,AN:AN,AQ:AQ,AS:AS,AV:AV,
AY:AY,BB:BB,BD:BD,BG:BG,BI:BI,BL:BL,BN:BN,BQ:BQ,BS:BS,
BV:BV,BY:BY,CB:CB,CD:CD,CG:CG,CI:CI,CL:CL,CN:CN,CQ:CQ,
CS:CS,CV:CV,CY:CY,DBB,DDD,DGG,DII,DLL,DNN,
DQQ,DSS,DVV,DYY,EB:EB,ED:ED,EG:EG,EI:EI,EL:EL,
EN:EN,EQ:EQ,ES:ES,EV:EV,EY:EY,FB:FB").Select (All this is in 1 row on
my macro)
Range("D1").Activate
Selection.EntireColumn.Hidden = True
End Sub
When I run it, it comes up with the error:
Runtime Error '1004':
Method 'Range' of object '_worksheet' failed.
When I click Debug it highlights the long range.
Does anybody know what I'm doing wrong?
Many thanks
Chris