我目前正在这样做Sheets("Sheet2").Range("A1").Value = 35
,但我想要一种方法来做到这一点Range("A1").Value = 35
,通过之前在单独的行上切换工作表。我试过Sheets("Sheet2").Select
,但这只会将它在末尾显示的工作表切换到工作表 2。
最佳答案
您可以使用 With
VBA 中的关键字来实现这一点。你可以转:Sheets("Sheet2").Range("A1").Value = 35
进入:
With Sheets("Sheet2")
.Range("A1").Value = 35
' do some other stuff
End With
注意前导。在范围之前。这意味着:使用
With
中的对象陈述或者,您可以将工作表分配给一个变量并使用它。
Dim ws as Worksheet
Set ws = Sheets("Sheet2")
ws.Range("A1").Value = 35
关于excel - 在 Excel VBA 中切换工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6310240/