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

时间:2016-06-13 15:03:11

标签: excel vba excel-vba

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

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

1 个答案:

答案 0 :(得分:1)

这有用吗?

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