简体   繁体   English

Excel VBA - 向下查看 A 列以获取特定值并隐藏活动单元格行下方的所有行?

[英]Excel VBA - Look down column A for specific value and hide all rows below activecell row?

I am using the following vba script to hide all rows with the matching cell value in column A of the Active Cell row:我正在使用以下 vba 脚本来隐藏 Active Cell 行的 A 列中具有匹配单元格值的所有行:

If Not Intersect(ActiveCell, Range("I:I")) Is Nothing And ActiveCell.Value = "-" Then

 BeginRow = 1
    EndRow = 50000
    ChkCol = 1

    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = ActiveCell.Offset(1, -8) Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        End If
    Next RowCnt

End If

So for instance if i have 5 rows all with the number 35 in column A like so:因此,例如,如果我有 5 行,A 列中的数字均为 35,如下所示:

A            I
35           Click to hide   <----- First Row
35           
35           
35           
35           

Then all these rows will be hidden.然后所有这些行都将被隐藏。 However, i don't want the row of the first instance to be hidden.但是,我不希望隐藏第一个实例的行。

Add two variables (a variant to hold the value to be compared and a boolean to validate the first value found)添加两个变量(一个变量来保存要比较的值,一个布尔值来验证找到的第一个值)

Dim vCllValue As Variant
Dim bl1stVal As Boolean

This is the revised code:这是修改后的代码:

If Not Intersect(ActiveCell, Range("I:I")) Is Nothing And ActiveCell.Value = "-" Then
    BeginRow = 1
    EndRow = 50000
    ChkCol = 1

    bl1stVal = False
    vCllValue = ActiveCell.Offset(1, -8).Value
    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = vCllValue Then
            If Not (bl1stVal) Then
                bl1stVal = True
            Else
                Cells(RowCnt, ChkCol).EntireRow.Hidden = True
End If: End If: Next: End If

Noticed that the code compares the value in the row below the ActiveCell I'm assuming that part is correct, otherwise let me know and will do the necessary adjustments.注意到代码比较了ActiveCell下面行中的值,我假设该部分是正确的,否则让我知道并将进行必要的调整。

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

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