VBA hidding columns baces on name rather than column number/letter

zborton

New Member
Joined
Jun 25, 2015
Messages
7
I currently have a user form with many check boxes to hide/show columns based on if a check box is checked or not. Right now I have the code refer to the columns based on thier letter and everything works great. I would like to have the code refer to the name of the columns rather than the letter to make everything more robust in case columns get deleted or moved around in the future.

Original working code:
Code:
Private Sub update_botton_Click()
'====================================================
'Update sheet based on checkbox selections
'====================================================

    With Sheets("sheet1")

        'Hides all the columns that steer are in
        Columns("ac:af").Hidden = Not (steer_cb)


Non-working idea of what I would like:
I have defined columns "ac:af" as the name "steer".
Code:
Private Sub update_botton_Click()
'====================================================
'Update sheet based on checkbox selections
'====================================================

    With Sheets("sheet1")

        'Hides all the columns that steer are in
        range("steer").Hidden = Not (steer_cb)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Non-working idea of what I would like:
I have defined columns "ac:af" as the name "steer".
Code:
Private Sub update_botton_Click()
'====================================================
'Update sheet based on checkbox selections
'====================================================

    With Sheets("sheet1")

        'Hides all the columns that steer are in
        range("steer")[B][COLOR="#FF0000"].EntireColumn[/COLOR][/B].Hidden = Not (steer_cb)
[Untested] What happens if you add what I show in red above?
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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