如何删除某个sheet之后的sheet?
How to delete the sheets after a certain sheet?
我的工作簿中有工作表 测试。还有其他工作表。我想删除出现在名为 Test 的工作表右侧的工作表。
如何在 VBA 中执行此操作?在这方面需要一些帮助。
编辑:
Set test= ThisWorkbook.Worksheets("Test")
For i = Sheets.Count To (test.Index + 1) Step -1
Delete Sheets(i)
Next
考虑:
Sub SheetKiller()
Dim i As Long
Dim j As Long
j = 0
For i = 1 To Sheets.Count
If Sheets(i).Name = "Test" Then
j = i
End If
Next i
If j = 0 Or j = Sheets.Count Then Exit Sub
Application.DisplayAlerts = False
For i = Sheets.Count To j + 1 Step -1
Sheets(i).Delete
Next i
Application.DisplayAlerts = True
End Sub
对已经提供的内容采取替代方法,如果您有 10 张工作表(工作表..?)并且想删除 Test 工作表之后的所有内容,只需不断删除sheet(Sheets("test").Index + 1)
直到 sheets.count 小于 Sheets("test").Index +1.
Application.DisplayAlerts = False 'take off the training wheels
Do While Sheets.Count > Sheets("test").Index
Sheets(Sheets("test").Index + 1).Delete
Loop
Application.DisplayAlerts = True
我的工作簿中有工作表 测试。还有其他工作表。我想删除出现在名为 Test 的工作表右侧的工作表。
如何在 VBA 中执行此操作?在这方面需要一些帮助。
编辑:
Set test= ThisWorkbook.Worksheets("Test")
For i = Sheets.Count To (test.Index + 1) Step -1
Delete Sheets(i)
Next
考虑:
Sub SheetKiller()
Dim i As Long
Dim j As Long
j = 0
For i = 1 To Sheets.Count
If Sheets(i).Name = "Test" Then
j = i
End If
Next i
If j = 0 Or j = Sheets.Count Then Exit Sub
Application.DisplayAlerts = False
For i = Sheets.Count To j + 1 Step -1
Sheets(i).Delete
Next i
Application.DisplayAlerts = True
End Sub
对已经提供的内容采取替代方法,如果您有 10 张工作表(工作表..?)并且想删除 Test 工作表之后的所有内容,只需不断删除sheet(Sheets("test").Index + 1)
直到 sheets.count 小于 Sheets("test").Index +1.
Application.DisplayAlerts = False 'take off the training wheels
Do While Sheets.Count > Sheets("test").Index
Sheets(Sheets("test").Index + 1).Delete
Loop
Application.DisplayAlerts = True