首页 > 代码库 > VBA_Excel_教程:表,格

VBA_Excel_教程:表,格

Sub 表和格()    定义工作表    Dim ws As Worksheet    get sheet by name【看到的表名,或序号1,2,3,...】,要加Set    Set ws = Worksheets("")    Set ws = Worksheets(1)

‘1,2:单元格内容(页面对应Range,坐标对应Cells) Debug.Print ws.Range("B1") Debug.Print ws.Cells(1, 1)
  
tmp = Cells(1, 1).Value ‘ 3:变量不用定义,当前写代码的Sheet
End Sub

 

Sub 遍历所有表()    For Each ws In Worksheets        Debug.Print ws.Name    NextEnd Sub

 

Sub 遍历部分表()    For i = 1 To 2 i不用定义        Dim ws As Worksheet        Set ws = Worksheets(i)                Debug.Print ws.Name    NextEnd Sub

 

VBA_Excel_教程:表,格