【问题标题】:Delete all rows with specific text and range删除具有特定文本和范围的所有行
【发布时间】:2016-03-11 03:59:58
【问题描述】:

到目前为止,这是我的代码。问题是它删除了第一行。我想排除第一行(标题)。因为我删除的行是重复的标题

[代码] 使第一行变暗 将 Lastrow 调暗 调暗 Lrow 只要 将 CalcMode 调暗 使 ViewMode 变暗

With Application
    CalcMode = .Calculation
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
End With


With ActiveSheet.Select


    ViewMode = ActiveWindow.View
    ActiveWindow.View = xlNormalView


    .DisplayPageBreaks = False


    Firstrow = .UsedRange.Cells(2).Row
    Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row


    For Lrow = Lastrow To Firstrow Step -2


        With .Cells(Lrow, "D")

            If Not IsError(.Value) Then

                If .Value = "Service Tower" Then .EntireRow.Delete

            End If

        End With

    Next Lrow

End With

ActiveWindow.View = ViewMode
With Application
    .ScreenUpdating = True
    .Calculation = CalcMode
End With [code]

【问题讨论】:

    标签: excel vba


    【解决方案1】:
    .UsedRange.Cells(2)
    

    是 UsedRange 第一行的第二个单元格。单元格从左到右然后从上到下计数(即“行优先”而不是“列优先”)

    你想要

    Firstrow = .UsedRange.Rows(2).Row
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-21
      • 2020-09-25
      • 2015-11-28
      • 1970-01-01
      • 2019-08-01
      • 2019-04-08
      • 2022-01-15
      • 1970-01-01
      相关资源
      最近更新 更多