I have a macro which auto-creates buttons in sheet4 based upon how many columns of data are in sheet3. Each button is auto-created to run a macro upon being clicked. The problem is that I need to know where on sheet4 the button which user clicked is located. Does a button trigger its nested cell as the ActiveCell? If that is the case this would be an easy program, however, using the activecell approach doesn't seem to work.
Here's my code which adds the buttons:
My goal is to have the macro which plays upon the button being clicked to sort data based upon which of the auto-created buttons was clicked. I think if we could simply set a variable based upon the button's nested cell it would be easy, but I'm not sure how to code that. I'm open to whatever way is easiest of tracking which button was clicked.
Thanks.
Here's my code which adds the buttons:
Code:
'Inputs Some_Title button
Dim oNewButton As Object
Dim sTitle As String
If Cells(WVar, 3).Value = "" Then
Cells(WVar, 3).Font.ColorIndex = 2
Cells(WVar, 3).Value = Cells(WVar, 1).Value
sTitle = Cells(WVar, 1).Value
'Sets Cell position and size variables
Sheets(4).Activate
Cells(WVar, 3).Activate
CellX = ActiveCell.Left
CellY = ActiveCell.Top
CellH = 23.25
CellW = 86.25
With ActiveSheet
Set oNewButton = .Buttons.Add(CellX, CellY, CellW, CellH)
With oNewButton
.Name = sTitle
.Characters.Text = "Some_Title"
.OnAction = "Some_Macro"
End With
End With
End If
My goal is to have the macro which plays upon the button being clicked to sort data based upon which of the auto-created buttons was clicked. I think if we could simply set a variable based upon the button's nested cell it would be easy, but I'm not sure how to code that. I'm open to whatever way is easiest of tracking which button was clicked.
Thanks.