尝试使我的列标题在删除和自动过滤器运行后保留在工作表中

时间:2019-08-02 18:38:44

标签: excel vba

我在删除功能和我的自动筛选器之间存在问题。当代码运行一次时,它会提取正确的数据,但是如果我第二次运行它,它将删除我的列标题。

更改范围不包括我的代码中的行。

Sub DeleteRowsAll()
  Dim iRow As Long
  Dim Rng As Range

  Application.ScreenUpdating = False
  Rows(1).Insert
  Range("E1").Value = "rabbitohs"
  With ActiveSheet
    .UsedRange
    iRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
    Set Rng = Range("E1", Cells(iRow, "E"))
    Rng.AutoFilter Field:=1, Criteria1:=""
    Rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .UsedRange
  End With
End Sub
Sub Auto_filter()
Dim sh As Worksheet
Set sh = ThisWorkbook.Worksheets("HP Service Manager")
With sh
On Error Resume Next
.ShowAllData

.Range("E1:N1").AutoFilter 1, "IM*"
End With
End Sub

I would like my header to remain in the sheet after the code executes.

0 个答案:

没有答案