VBA worksheet move
时间: 2023-10-09 18:12:43 浏览: 99
Office VBA
To move a worksheet in VBA, you can use the `Move` method of the `Worksheet` object. Here's an example:
```vb
Sub MoveWorksheet()
Dim ws As Worksheet
' Set the worksheet object
Set ws = ThisWorkbook.Sheets("Sheet1")
' Move the worksheet to the end
ws.Move After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
' Move the worksheet to a specific position
' ws.Move Before:=ThisWorkbook.Sheets(2)
End Sub
```
In this example, the `Move` method is used to move the worksheet named "Sheet1" to the end of the workbook. Alternatively, you can use the `Before` parameter to specify the position before which you want to move the worksheet. Uncomment the corresponding line in the code and modify the sheet index as needed.
Remember to replace "Sheet1" with the actual name of the worksheet you want to move.
阅读全文