除了第一张或当前工作表外,我想删除每张工作表中的第一列(A:A)。有人可以帮助我。 我使用以下代码删除每个工作表的第一列。
Sub deletefirstcolum()
Dim ws As Worksheet
For Each ws In Sheets
ws.Cells(1, 1).EntireColumn.Delete
Next ws
End Sub
请帮忙。如何排除第一张或当前的表格。
答案 0 :(得分:1)
在工作表上添加If
条件:
Sub deletefirstcolum()
Dim ws As Worksheet
For Each ws In Sheets
If Not ws Is ActiveSheet Then
ws.Cells(1, 1).EntireColumn.Delete
End If
Next ws
End Sub
答案 1 :(得分:0)
测试ws =是否为活动工作表:
Sub deletefirstcolum()
Dim aWs As Worksheet
Set aWs = ActiveSheet
Dim ws As Worksheet
For Each ws In Sheets
If aWs.Name <> ws.Name Then
ws.Cells(1, 1).EntireColumn.Delete
End If
Next ws
End Sub