Hiding an ActiveX button when hiding columns

crobaseball

Board Regular
Joined
Mar 14, 2014
Messages
59
I am putting several buttons into my spread sheet and would prefer to use ActiveX controls rather than form controls. But I also need to hide the buttons from the end user (controls are to update data and will be used by the person who maintains the workbook). When I go to hide the columns, the ActiveX button doesn't hide with it. On the other hand, if I use a Form Control Button instead, it does indeed disappear when I hide the columns. Is there any way to get the ActiveX button to hide when hiding the columns?

Thanks!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
How do the columns get hidden? One option is to set the Visible property to False when the column is hidden.
 
Upvote 0
Can I have this be a part of the vba of the sheet itself? I can either have someone hide the columns manually, or I can create another button to do this. I assume the button will reappear when the columns are unhidden?
 
Upvote 0
You would have to hide and unhide the buttons using vba. If the button you want to hide/unhide is named CommandButton1 then to hide the button use the following:
CommandButton1.Visible=False
To unhide the button use
CommandButton1.Visible=True
If you have a button to hide the column just add the first line above to that code and similarly, if you have a button to unhide the column add the second line.
The above method is pretty straightforward. I'm not sure if hiding/unhiding a column triggers a change event or not without testing, but if it does the code could be added there as well.
 
Upvote 0
I know the code to hide or unhide the button, what i need is for it to do so when the columns are hidden, then to unhide when the columns are unhidden. I can certainly do this using vba/button when hiding . . . but there's no way to do it when unhiding. Or there would be a button visible to do so. I guess I could just have a macro which someone could run to do so and lock out the macro's, but this really isn't user friendly the way I'd like it to be
 
Upvote 0
The following code, using Column H as the hidden column will hide/unhide the button
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Columns("H:H").EntireColumn.Hidden = True Then
    Me.CommandButton1.Visible = False
End If
If Columns("H:H").EntireColumn.Hidden = False Then
    Me.CommandButton1.Visible = True
End If
End Sub
 
Upvote 0
By the way, the above code doesn't execute when the column is hidden/unhidden, but when you select a cell after hiding/unhiding or whenever any selection change occurs.
 
Upvote 0
I realized that wasn't clear: what I meant more specifically . . . The code you wrote, does that go into the vba of the actual sheet? As opposed to in a separate module?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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