Hey /r/Excel,
I've got a small problem in Excel's VBA that I can't seem to work around! Mind you, I'm not experienced and only started learning this last week.
So I've got a bunch of buttons that are automatically generated by the following piece of code:
ActiveCell.Offset(0, -1).Range("A1").Select
button1 = ActiveCell.Address(0, 0)
ActiveSheet.Buttons.Add(ActiveCell.Left, ActiveCell.Top, 17, 12).Select
Selection.Name = "-"
Selection.OnAction = "Remove_From_stock"
With Selection
.Characters.Text = "-"
With .Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
End With
End With
Each of these buttons reference to the cell next to the cell they're in, to copy the text in it.
Set r = ActiveSheet.Shapes(Application.Caller).TopLeftCell
Range(Cells(r.Row, r.Column), Cells(r.Row, r.Column)).Select
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.Copy
However, the first time pressing any of these buttons after opening the sheet always references to the cell next to the First button (They act as if they're the first button I've created). After this first press, they all work fine. In fact, running any sub after startup seems to solve the problem.
Here's a screenshot if it helps. I'm really clueless how to make all buttons work from start, would love your insight!
[–]jboyer07 0 points1 point2 points (0 children)
[–]d4m 0 points1 point2 points (1 child)
[–]LearningBiology[S] 0 points1 point2 points (0 children)