我目前正在做这个Sheets("Sheet2").Range("A1").Value = 35
,但我想要一种方法来做到这一点Range("A1").Value = 35
,通过切换表单在一个单独的行之前。我试过Sheets("Sheet2").Select
,但只有切换到纸2在Excel VBA中切换工作表
-2
A
回答
8
您可以使用VBA的With
关键字来实现这一目标。您可以打开:
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
5
这显示在结束薄片是如何做到这一点
Sub a()
Sheets("Sheet2").Activate
Range("A1").Value = 35
End Sub
相关问题
- 1. 的Excel - VBA切换工作簿
- 2. 已禁用VBA切换工作表
- 3. Excel VBA:切换按钮只能在右键点击工作
- 4. Excel VBA中从Excel工作表
- 5. Excel VBA工作表事件在隐藏/取消隐藏之间切换
- 6. Excel的VBA:工作表
- 7. 在工作表( “工作表Sheet1”)Excel VBA中崩溃
- 8. 隐藏工作簿/工作表Excel VBA
- 9. Excel VBA - 无法在其他工作簿中复制工作表
- 10. excel vba表格已关闭,但我无法切换到其他.xlsm工作簿
- 11. 使用VBA仅在活动工作表之间切换
- 12. VBA中的切换工作表无法按我希望的方式工作
- 13. 在Excel工作表中转换时区
- 14. 如何切换到工作表?
- 15. Excel VBA自己的功能,在工作表中改变工作表中的值
- 16. 更换在Excel工作表的列表
- 17. VBA宏不能在Excel 2016中工作
- 18. 使用VBA在Excel工作表中创建表格
- 19. excel vba在新工作表中的多个图表
- 20. Powerpoint VBA从Excel切换回powerpoint
- 21. VBA Office 2007创建2003 Excel工作表
- 22. Excel VBA - 工作表被太快保护
- 23. Excel VBA countifs工作表函数
- 24. 使用excel激活工作表VBA
- 25. Excel VBA - 工作表数据比较
- 26. Excel VBA:虚拟地排列工作表?
- 27. Excel的VBA - 从工作表Sheet1
- 28. Excel VBA限制工作表调色板
- 29. 通过VBA隐藏excel工作表
- 30. Excel VBA函数在Visual Basic中工作,但在工作表中失败
这两个也都是对的 – datatoo 2011-06-11 02:14:22
+1。最好使用变量,避免使用选择 – brettdj 2011-10-30 00:57:10