|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 excel玉米 于 2024-5-6 10:36 编辑
因为你【对方账号】包含在要保留的【对方账号名称】列名称里,所以它保留了不予删除
- Sub DeleteSelectedColumns()
- Dim ws As Worksheet
- Dim rDel As Range
- Dim HeaderCell As Range
- Dim sKeepHeaders As Variant
- Dim sDelimiter As String
- Dim i As Integer
- sKeepHeaders = Array("序号", "凭证号", "账户余额", "对方账号", "对方行名")
- For Each ws In Worksheets
- Set rDel = Nothing
- For Each HeaderCell In ws.Range("A1", ws.Cells(1, ws.Columns.Count).End(xlToLeft)).Cells
- For i = LBound(sKeepHeaders) To UBound(sKeepHeaders)
- If HeaderCell = sKeepHeaders(i) Then
- If Not rDel Is Nothing Then Set rDel = Union(rDel, HeaderCell) Else Set rDel = HeaderCell
- End If
- Next i
- Next HeaderCell
- If Not rDel Is Nothing Then rDel.EntireColumn.Delete
- Next ws
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|