作者:LeonaL_1巛980 | 来源:互联网 | 2023-05-19 05:05
IamlookingforaVBAscriptthatwilldeleteallcolumnsinallworksheetsofaanexcelworkbook
I am looking for a VBA script that will delete all columns in all worksheets of a an excel workbook except those named:
我正在寻找一个VBA脚本,它将删除excel工作簿的所有工作表中的所有列,除了那些名为:
Date
Name
Amount Owing
Balance
the following code is working but it only apply in the active worksheet :
以下代码正在运行,但它仅适用于活动工作表:
Sub DeleteSelectedColumns()
Dim currentColumn As Integer
Dim columnHeading As String
For currentColumn = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value
'Check whether to preserve the column
Select Case columnHeading
'Insert name of columns to preserve
Case "Date", "Name", "Amount Owing", "Balance"
'Do nothing
Case Else
'Delete the column
ActiveSheet.Columns(currentColumn).Delete
End Select
Next
End Sub
Can someone help me modify this code to apply on all worksheets of a workbook ?
有人可以帮我修改此代码以应用于工作簿的所有工作表吗?
1 个解决方案