variable column selection

nigelandrewfoster

Well-known Member
Joined
May 27, 2009
Messages
747
Hi. I want to replace
Columns("a:g") with a variable, so I can select a variable range of columns. Can this easily be done without looping, please?
Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi MIck. No, the number of columns I want to hide varies, so I need the equivalent of
x=1
y=7
Columns(x:y).Hideentire columns (or whatever)=true
 
Upvote 0
Hi MIck. No, the number of columns I want to hide varies, so I need the equivalent of
x=1
y=7
Columns(x:y).Hideentire columns (or whatever)=true
 
Upvote 0
Possibly:-
Code:
Dim x, y
x = 3
y = 5
Columns.Hidden = False
'Columns (C to G)
Columns(Chr(64 + x)).Resize(, y).Hidden = True
Mick
 
Upvote 0
Try stepping through this code a line at a time, See if any of these lines work:-
It works in xl2002
Code:
Dim x, y
x = 3
y = 5
Columns.Hidden = False
'Columns (C to G)
MsgBox Chr(64 + x)
MsgBox Columns(Chr(64 + x)).Resize(, y).Address
MsgBox Columns(Chr(64 + x) & ":" & Chr(64 + 3)).Address
'Columns(Chr(64 + x)).Resize(, y).Hidden = True
Columns(Chr(64 + x) & ":" & Chr(64 + x)).Resize(, y).Hidden = True
also
Code:
Dim x, y
x = 3
y = 5
MsgBox Range(Chr(64 + x) & ":" & Chr(64 + x)).Resize(, y).Address

Mick
 
Last edited:
Upvote 0
Something along lines of:

Code:
Sub test()
    a = 3
    b = 7
    Range(Columns(a), Columns(b)).Select
End Sub
 
Upvote 0
Thankd guys. IT worked when I typed it in again. Using phone for internet so couldn't copy and paste. No idea why it came up with that error before. Much appreciated. Your efforts are not wasted. I have learned a lot from these examples.
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top