返回列表 上一主題 發帖

[發問] 依照標題關鍵字指定欄位條件而刪除該攔

回復 5# billchenfantasy
  1. Sub ex()
  2. Dim Rng As Range, C As Range
  3. ar = Array("PLAN_NO", "PlAN_DAT")
  4. For Each C In Rows(1).SpecialCells(xlCellTypeConstants)
  5. n = 0
  6.    For Each a In ar
  7.      If InStr(UCase(C), UCase(a)) > 0 Then
  8.      n = n + 1
  9.      End If
  10.      If n = 0 Then
  11.         If Rng Is Nothing Then
  12.            Set Rng = C
  13.            Else
  14.            Set Rng = Union(Rng, C)
  15.         End If
  16.      End If
  17.   Next
  18. Next
  19. Rng.EntireColumn.Delete
  20. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 8# billchenfantasy
第17行的Next要往前放
  1. Sub ex()

  2. Dim Rng As Range, C As Range
  3. ar = Array("PLAN_NO", "PLAN_DAT")
  4. For Each C In Rows(1).SpecialCells(xlCellTypeConstants)
  5. n = 0
  6.    For Each a In ar
  7.      If InStr(UCase(C), UCase(a)) > 0 Then
  8.      n = n + 1
  9.      End If
  10.    Next
  11.      If n = 0 Then
  12.         If Rng Is Nothing Then
  13.            Set Rng = C
  14.            Else
  15.            Set Rng = Union(Rng, C)
  16.         End If
  17.      End If
  18. Next
  19. Rng.EntireColumn.Delete
  20. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 地上種了菜,就不易長草;心中有善,就不易生惡。
返回列表 上一主題