在我的工作簿中,我在不同的工作表中有很多ToggleButton,它让我到同一张表(SheetX),然后从那张表中我想返回按下ToggleButton的地方。
有没有更好的方法来执行无限的If / End If语句
希望我足够清楚
Private Sub CommandButton12_Click()
If Sheets("T1").ToggleButton1.Value = True Or Sheets("T2").ToggleButton1.Value = True Then
Sheets("T2").Select
If Sheets("T1").ToggleButton1.Value = True Or Sheets("T2").ToggleButton1.Value = True Or Sheets("T3").ToggleButton1.Value = True Then
Sheets("T3").Select
End If
'So on and on and on
Else
Sheets("T1").Select
End If
End Sub
答案 0 :(得分:0)
根据Scott的建议,您可以使用全局变量并让工作表1使用按钮返回上次保存的项目,例如:
Public r as Long, Public c as Long, Public s as Worksheet
Sub Global_Hold_Macro()
'You would put "Globlal_Hold_Macro" in each togglebutton
r = Activecell.Row
c = Activecell.Column
s = Activesheet.Name
End Sub
Sub Sheet1_Toggle_To_Go_Back()
s.cells(r,c).Select
End Sub
修改强>
将显示此内容以调用特定的命名形状,在本例中为按钮:
Public r as String
Public c as String
Sub Global_Hold_Macro()
'You would put "Globlal_Hold_Macro" in each togglebutton
r = Application.Caller
c = Activesheet.Name
End Sub
Sub Sheet1_Toggle_To_Go_Back()
Sheets(c).Activate
Sheets(c).Shapes(r).Select
End Sub
如果您使用某些类型的按钮/形状,这可能不起作用。