[英]Excel VBA - Look down column A for specific value and hide all rows below activecell 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
因此,例如,如果我有 5 行,A 列中的數字均為 35,如下所示:
A I
35 Click to hide <----- First Row
35
35
35
35
然后所有這些行都將被隱藏。 但是,我不希望隱藏第一個實例的行。
添加兩個變量(一個變量來保存要比較的值,一個布爾值來驗證找到的第一個值)
Dim vCllValue As Variant
Dim bl1stVal As Boolean
這是修改后的代碼:
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
注意到代碼比較了ActiveCell
下面行中的值,我假設該部分是正確的,否則讓我知道並將進行必要的調整。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.