且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

基于列值删除宏中的行

更新时间:2023-02-02 21:02:01


  1. 启用AutoFilter
  2. 使用逻辑1
  3. 在列上设置过滤器为列标题以外的所有可见数据选择整行
  4. 在主页功能区上,选择查找&选择 - >转到特别 - >可见细胞仅
  5. 右键单击在选择的区域,然后删除行
  6. 关闭自动筛选

关注应该为您执行此操作的VBA代码。请注意您需要修改的评论。

Following VBA code that should do this for you. Note the comments where you will need to edit.

Sub Macro1()

   

    Dim rngFiltered As Range

   

   使用工作表("Sheet1")   '编辑" Sheet1"到您的工作表名称

        .UsedRange.Rows(1).AutoFilter

       

      &的 '继行编辑字段:= 6至与所述一个的 强列号>

        .AutoFilter.Range.AutoFilter字段:= 6,标准1:=&QUOT 1 QUOT;

       

       使用.AutoFilter.Range

           设置rngFiltered = .Offset(1,0)_

               &NBSP ;                .Resize(.Rows.Count - 1,.Columns.Count)_

                                 .SpecialCells(xlCellTypeVisible)

       结束与$
      

        rngFiltered.EntireRow.Delete shift:= xlUp

        .AutoFilterMode = False

        Application.Goto .Range(" A1"),scroll:= True   
 '可选

   结束于$
结束子

Sub Macro1()
   
    Dim rngFiltered As Range
   
    With Worksheets("Sheet1")   'Edit "Sheet1" to your sheet name
        .UsedRange.Rows(1).AutoFilter
       
       'Following line edit Field:=6 to the column number with the one's
        .AutoFilter.Range.AutoFilter Field:=6, Criteria1:="1"
       
        With .AutoFilter.Range
            Set rngFiltered = .Offset(1, 0) _
                                .Resize(.Rows.Count - 1, .Columns.Count) _
                                .SpecialCells(xlCellTypeVisible)
        End With
       
        rngFiltered.EntireRow.Delete shift:=xlUp
        .AutoFilterMode = False
        Application.Goto .Range("A1"), scroll:=True     'Optional
    End With
End Sub