我正在尝试编写一个隐藏所有空白行的宏,直到检测到值“ stop”为止,但是当代码到达“ Entirerow.hidden = True
”部分时,我收到了一条溢出错误消息。如果有人可以帮助我解决此问题,我将不胜感激?
Dim Count as Integer
Count = 0
Dim Rge as Range
Set Rge = Sheets("ForPrint").Range("b24").Offset(count,0)
Do Until Rge.Value = "Stop"
If Rge.Value = "" Then
Rge.EntireRow.Hidden = True
End if
Count = Count + 1
Loop
答案 0 :(得分:0)
实际上您不是在Loop中设置范围:
这个简单的循环可以完成工作:
Dim Rge As Range
Dim cl As Range
Set Rge = Sheets("ForPrint").Range("B:B").Find("Stop")
For Each cl In Sheets("ForPrint").Range("B24:B" & Rge.Row).SpecialCells(xlCellTypeBlanks)
cl.EntireRow.Hidden = True
Next
否则在您的代码中尝试以下操作:
Dim Count As Integer
Count = 0
Dim Rge As Range
Set Rge = Sheets("ForPrint").Range("b24").Offset(Count, 0)
Do Until Rge.Value = "Stop"
Set Rge = Sheets("ForPrint").Range("b24").Offset(Count, 0)
If Rge.Value = "" Then
Rge.EntireRow.Hidden = True
End If
Count = Count + 1
Loop