Having trouble with Hide/Show Macro Button

excelgirl0610

New Member
Joined
Dec 20, 2016
Messages
5
Hi there,

I am creating a simple grocery worksheet that has some instructions on it that I'd like to give users the options to hide/show. I made a button, created the macro, inserted it onto a module specifically for that button, and then tested it to see if it works. The first time I clicked it, the button did exactly like it was supposed to. The second time I tried, it won't do it. Now instead, a duplicate button pops up for a brief moment when I click the button, but nothing else happens. What am I doing wrong? I am using Excel 2016 btw. Here is what the code currently looks like:

Private Sub HideInstructions_Click ()
'
' HideColumn Macro
'

'
Columns ("A:I") .Select
Selection.EntireColumn.Hidden = True
End Sub

Am I doing something wrong here? Workbook was protected beforehand, but I disabled those functions. Also, VBA is not password protected in any way.

I'm sorry if this sounds really silly, but I am re-learning how to use Macros (and I actually never learned VBA!) so just hoping someone here can guide me. Thank you!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
How are you Unhiding the columns ??
AND
you don't need to Select the columns to hide them !!

Code:
Private Sub HideInstructions_Click ()
Columns("A:I").EntireColumn.Hidden = True
End Sub

Also, the button doesn't reside within columns A:I does it ......so it 's getting hidden with the columns ???
 
Last edited:
Upvote 0
To Toggle the visibility, you could use code like

Code:
With Range("A:I").EntireColumn
    .Hidden = Not (.Hidden)
End With
 
Upvote 0
How are you Unhiding the columns ??
AND
you don't need to Select the columns to hide them !!

Code:
Private Sub HideInstructions_Click ()
Columns("A:I").EntireColumn.Hidden = True
End Sub

Also, the button doesn't reside within columns A:I does it ......so it 's getting hidden with the columns ???


I see...Didn't know that about the selection part. But no, the button isn't being hidden. I was going to use a separate button to unhide, but hadn't gotten that far yet because I couldn't get the first button to work yet.
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,988
Members
448,935
Latest member
ijat

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