How do I add 100 or a thousand form scrolls bars (not active x) to every 4th row covering two or three cells eg Starting from D3 E3 and F3 then D7 E7 etc Which adjust cell in B3 then B7 respectively. Each scroll bar having the ability to adjust a cell by +-100 ??
I know how to do this with a form button to activate a sub based on the row reference of the button but now I need to do it with a scroll bar see below:
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("TRADEDIARY").Range("AD" & CStr(rowNumber)).Value = 1
Application.ScreenUpdating = True
End Sub
Aucun commentaire:
Enregistrer un commentaire