简体   繁体   English

VBA不循环过滤的行

[英]VBA not looping filtered rows

I have this big excel file that is automated to do some processes. 我有一个很大的Excel文件,可以自动执行一些流程。 Today, I figured there is an issue with one of the columns and I need to fix it. 今天,我发现其中一个专栏存在问题,我需要对其进行修复。 to fix it I am generated this code below to filter column N to show all '#N/A'. 为了解决这个问题,我在下面生成了此代码来过滤N列以显示所有“#N / A”。 with the filtered rows, I want to check and see if the offset to the right 2 columns has the value "Available". 与筛选的行,我想检查,看看右边2列的偏移量是否具有值“可用”。 if it does, I want to loop through all column N and replace the '#N/A' with 'Unkown'. 如果是这样,我要遍历所有N列,并将“#N / A”替换为“未知”。 but the code I generated only works for the first filtered cell and doesn't loop. 但我生成的代码仅适用于第一个过滤的单元格,并且不会循环。

Sub tess()
ActiveSheet.Range("$C$1:$AR$468").AutoFilter Field:=12, Criteria1:="#N/A"

ActiveSheet.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(, 12).Select

Dim lr
lr = ActiveSheet.UsedRange.Rows.CountLarge

For Each cell In Range("n1:n" & lr)
If ActiveCell.Value = CVErr(xlErrNA) And ActiveCell.Offset(, 2).Value = "Available" Then

  ActiveCell.Value = "Unkown Person"

  End If
Next cell

End Sub

Thank you. 谢谢。

you can avoid looping by adding another filter: 您可以通过添加另一个过滤器来避免循环:

Sub tess()
    With ActiveSheet.Range("$C$1:$AR$468")
        .AutoFilter Field:=12, Criteria1:="#N/A"
        .AutoFilter Field:=14, Criteria1:="Available"
        If Application.WorksheetFunction.Subtotal(103, .Columns(12)) > 1 Then .Offset(1, 11).Resize(.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible).Value = "Unkown Person"
        .Parent.AutoFilterMode = False
    End With
End Sub

您应该在For循环中引用“单元”,而不是“ ActiveCell”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM