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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,586
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
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

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,348
To Toggle the visibility, you could use code like

Code:
With Range("A:I").EntireColumn
    .Hidden = Not (.Hidden)
End With
 
Upvote 0

excelgirl0610

New Member
Joined
Dec 20, 2016
Messages
5
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,190,646
Messages
5,982,114
Members
439,755
Latest member
nicos18

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