【发布时间】:2015-05-29 09:23:02
【问题描述】:
问题已解决如何使多个按钮引用不同的相邻偏移单元格
子测试器() 将 btn 变暗为对象 调暗为范围 暗淡我只要 将 lastRow 变暗
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
上述解决方案效果很好,但每当我单击按钮时计算起来有点慢。我需要它是即时的,但它会挂起 5 秒...有什么办法可以避免这种情况吗?
【问题讨论】: