Question has been solved how to make multiple buttons reference different adjacent offset cells
Sub Tester() Dim btn As Object Dim rng As Range Dim i As Long Dim lastRow As Long
lastRow = 99999 'Modify as needed this will be the last possible row to add a button
For i = 2 To lastRow Step 4
Set rng = ActiveSheet.Cells(i, 21) 'Column 2, row i
'## Create the button object and assign a variable to represent it
Set btn = ActiveSheet.Buttons.Add(1, 1, 1, 1)
'## use the btn variable to manipulate the button:
With btn
.Top = rng.Top
.Left = rng.Left
.width = rng.width
.height = rng.RowHeight
.OnAction = "offsetRelative"
.Caption = "Close"
End With
Next
End Sub
Sub offsetrelative()
Dim rowNumber As Long
'## Get the row number of the button:
rowNumber = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
Application.ScreenUpdating = False
Sheets("Sheet6").Range("AD" & CStr(rowNumber)).Value = 1
Application.ScreenUpdating = True
End Sub
the above solution works great but is a little slow to calculate whenever I click a button. I need it to be instant but it hangs for 5 seconds...is there any way to avoid this?