VBA Code Hide/Unhide columns with Checkboxes

Marty1

New Member
Joined
Aug 16, 2011
Messages
5
Hello Everyone,

This is my first time to the forum and newbie to Excel VBA.
I have a userform labels role_selection with 6 checkboxes. Each checkbox with the caption labels as follow: Revenues, Erevenues, Occupancy, ADR, EADR and RevPAR.
These checkboxes refers to a tab where I have all the datas to hide / unhide

My question is how can i write a program to determine which checkbox is selected (true or false) and hide boxes which are unchecked (and unhide the selected boxes).

I basically need a vba code that I can assign to a command button as follows:

Hide entire columns: AI:AX

If cell BC3 = TRUE, then unhide AJ and AR columns
If cell BC4 = TRUE, then unhide AK and AS columns
If cell BC5 = TRUE, then unhide AL and AT columns
If cell BC6 = TRUE, then unhide AM and AU columns
If cell BC7 = TRUE, then unhide AN and AV columns
If cell BC8 = TRUE, then unhide AO and AW columns

Thanks you very much for your help
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi Marty1,

This code should do it:

Code:
With Worksheets("myworksheet")
   .Columns("AI:AX").Hidden = True
   If Range("BC3") = True Then
      .Columns("AJ").Hidden = False
      .Columns("AR").Hidden = False
   End If
   If Range("BC4") = True Then
      .Columns("AK").Hidden = False
      .Columns("AS").Hidden = False
   End If
   If Range("BC5") = True Then
      .Columns("AL").Hidden = False
      .Columns("AT").Hidden = False
   End If
   .
   .
   .
End With

where myworksheet is the name of the worksheet containing the data you want to hide/unhide.

Keep Excelling.

Damon
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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