I have 12 buttons across E3:P3. Each button would run the same macro "Hide", which simply hides the column. I know I could create 12 separate macros for each button. How can I have one macro "Hide" and for it to know which button the user clicked on thus knowing which column to hide? Each button is named button 1, 2, 3, and so on. So, if my macro "Hide" knew that Button2 was pressed then it would hide columns("F"). I just can't figure out how to pass the name of the button to the "Hide" macro. I thought if I could pass it on I then could use Case Select?
What I came up with to create the buttons is:
What I came up with to create the buttons is:
VBA Code:
Dim i As Long, rng As Range
Set rng = Range("E3")
For i = 1 To 12
ActiveSheet.Buttons.Add(rng.Offset(0, i - 1).Left, rng.Offset(0, i - 1).Top, rng.Offset(0, i - 1).Width, rng.Offset(0, i - 1).Height).Select
Selection.OnAction = "Hide"
Selection.Characters.Text = "Hide"
Selection.Name = "Button" & i
Next i