直到循环检查单元在VBA中不是空的?

问题描述:

目前我有代码检查找到的第一个“)”右侧的单元格是否为空,如果不是,则它将“A”列向下移动。我似乎无法弄清楚如何让这个继续运行,直到paren右边的单元格为空。任何帮助,将不胜感激。谢谢。直到循环检查单元在VBA中不是空的?

Sub SeekParen() 
    Dim C As Range, wheree As Range, whatt As String 
    whatt = ")" 
    Set C = Range("A1:A10") 
    Set wheree = C.Find(what:=whatt, after:=C(1)).Offset(0, 1) 
    If Not IsEmpty(wheree.Address(0, 0)) Then 
     Range("A2").Select 
     Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 
    End If 
End Sub 

这工作?

Sub SeekParen() 
Dim C As Range, wheree As Range 
Dim whatt As String 
Dim TotalCycle As Long, CounterCycle As Long 
whatt = ")" 
Set C = Range("A1:A10") 

Set wheree = C.Find(what:=whatt, after:=C(1)).Offset(0, 1) 
TotalCycle = Application.WorksheetFunction.CountIf(C, whatt) 
For CounterCycle = 1 To TotalCycle 
If wheree.Value <> "" Then 
Range("A2").Select 
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 
Set wheree = C.Find(what:=whatt, after:=C(wheree.Row)).Offset(0, 1) 
Else 
Exit For 
End If 
Next CounterCycle 
End Sub 
+0

谢谢。这工作得很好。出于某种原因,如果您不止一次运行它,它会将paren带到我想要的位置,但是第一次将它放到所需位置上方的一个单元格中。有任何想法吗? – Rob

+0

由于第一次执行时项目的大小不一样,这是预期的行为。您需要插入整行,而不是只插入第一列。 – Sgdva