Independent Macro Buttons on Same Worksheet

dbtech

New Member
Joined
Feb 12, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hello Experts!

I have been trying to create separate buttons to a worksheet that can be triggered independently of each other. So far I've only been able to make the 2nd one work if the first one has already been activated. These would be for hiding and unhiding separate groups of columns in the spreadsheet.

I want the on-off function to operate so that while one group of columns is showing, the other can be hidden and vice versa.

Any help you could provide would be greatly appreciated.

Thanks in advance!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Can you please share the code that you have so far?
 
Upvote 0
Can you please share the code that you have so far?
Hi Severynm,

Thanks for your reply. Here's what I have so far:

Private Sub ToggleButton1_Click()
Dim xAddress As String
xAddress = "J:M"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
End If
End Sub

Private Sub ToggleButton2_Click()
Dim xAddress As String
xAddress = "N:Q"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
End If
End Sub


Hope this helps. Thanks again.
 
Upvote 0
I have been trying to create separate buttons to a worksheet that can be triggered independently of each other. So far I've only been able to make the 2nd one work if the first one has already been activated. These would be for hiding and unhiding separate groups of columns in the spreadsheet.

I want the on-off function to operate so that while one group of columns is showing, the other can be hidden and vice versa.
It does definitely help, but I'm still a little confused as to what you are looking for, as the items i highlighted seem to contradict each other. Can you elaborate a little more?
 
Upvote 0
I have 4 columns in two separate categories (4 columns each) on the same sheet that I would like to be able to hide and unhide at will. I want one button to hide/unhide one set of columns and another for the other set of columns. Right now, the second button only works if the first button is actuated. This causes both sets of columns to be hidden. I want the buttons to be independent of each other (that is, functioning as two separate buttons) and not have their actions connected as they are now. The first button should be able to hide/unhide the first set of columns and the second button should be able to hide/unhide the second set of columns without relying on the first button's operation. Button2 does not work without Button1.

I hope I did a better job of explaining this time. :)
 
Upvote 0
I found the answer. I was calling the same button in both codes. Once it was changed to the correct name, it worked like a charm!
 
Upvote 0
Solution

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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