2017-09-20 113 views
0

试图查看列中的单元格,然后查明单元格是否具有6/7字符以及是否有i。VBA有条件的跳过语句循环

然后复制。

Sub ctest() 
Dim i As Long 
For i = 1 To 5000 
    With Range("AR" & i) 

     If Left(.Value, 1) <> "i" Then GoTo NextIteration Else 

     If Len(.Value) = 6 Then .Copy Destination:=.Offset(, 2) 
     If Len(.Value) = 7 Then .Copy Destination:=.Offset(, 2) 

NextIteration: 
    End With 

Next i 
End Sub 

但这似乎并没有工作以及.. 谢谢你们。

+0

子CTEST() 昏暗我只要 对于i = 1到5000 随着范围( “AR” &i) If Left(.Value,1)<>“i”Then GoTo NextIteration Else If Len(.Value)= 6 Then .Copy Destination:=。Offset(,2) 如果Len(.Value )= 7然后。复制目标:=。偏移(,2) NextIteration: End With Next i End Sub – user3724482

+0

Define“但这似乎不起作用。” - 它给出了一个错误?它不符合你的期望吗? – YowE3K

回答

0

如果你只是想跳过循环,为什么不使用基本if声明

Sub ctest() 
Dim i As Long 
For i = 1 To 5000 
    With Range("AR" & i) 

     If Left(.Value, 1) = "i" Then 
      If Len(.Value) = 6 Then .Copy Destination:=.Offset(, 2) 
      If Len(.Value) = 7 Then .Copy Destination:=.Offset(, 2) 
     End If 

    End With 

Next i 
End Sub 
+0

这是一个好主意....然而, 如果左(.Value,1)=“我”然后 这条线似乎并没有得到很好的认识。嗯值是全部空白 – user3724482