[英]Excel vba hide rows until value
我想在Excel中隐藏X到X的第7行,其中X是A列中值的第一个实例上方的第6行。
Google似乎提出了一些看起来对我而言太复杂的东西。
到目前为止,我的基本知识是:
'Select Rows 7 through 3 rows before the first instance of any text in column A, then hides them
Rows("7:62").Select
' have to update the 62 above to look for text and hide based on that
Selection.Rows.Group
Selection.EntireRow.Hidden = True
在我的Sub中。 我只需要弄清楚如何将62更改为通常在60左右的可变单元格,但并不总是62的确切值。
尽量避免使用“ Select
。
strValueToFind = "What ever the value you are trying to find in column A is"
With Sheets("Sheet1")
'Find the row containing the value
intFoundRow = .Range("A:A").Find(What:= strValueToFind, _
LookIn:=xlValues, _
LookAt:=xlWhole).Row
'Now hide Rows 7 through 6 above the row we found
.Rows("7:" & intFoundRow - 6).Hidden = True
End With
希望这并不太复杂。 :)
您的叙述说“上面有6行”,而代码说“之前3行” 。 我通常相信代码。 由于涉及数学运算,因此这很重要,并确保您不尝试隐藏第7行上方的行。
Dim rw As Variant
rw = Application.Match(Chr(42), Range("A8:A1048576"), 0)
If Not IsError(rw) Then
rw = Application.Max(rw + 4, 7)
Range("A7:A" & rw).EntireRow.Hidden = True
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.