How to refer to named ranges & column numbers in VBA?

ajmckenna

Board Regular
Joined
Oct 7, 2002
Messages
145
I want to unhide columns. I have named worksheet cells that calculate the column numbers to unhide. I have named them col_start & col_ end. how do I make this work
say col_start = 3 & col_end=500


Column("col_start:col_end"):EntireColumn.hidden = True

I don't even think this works, can you refer to columns as #'s????
Column("3:500"):EntireColumn.hidden = True

Thanks
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
On 2002-10-28 18:03, ajmckenna wrote:
I want to unhide columns. I have named worksheet cells that calculate the column numbers to unhide. I have named them col_start & col_ end. how do I make this work
say col_start = 3 & col_end=500
Column("col_start:col_end"):EntireColumn.hidden = True

I don't even think this works, can you refer to columns as #'s????
Column("3:500"):EntireColumn.hidden = True

Thanks

Columns are named with letters, so, no, you can't do that, at least not directly. You can do, however, something like this:

Range(Cells(1,col_start), Cells(1,col_end)).EntireColumn.Hidden = True
 

Forum statistics

Threads
1,143,640
Messages
5,719,984
Members
422,256
Latest member
downeybm

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
Top