Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA如果然后与For Each循环结合使用_Excel_Vba - Fatal编程技术网

Excel VBA如果然后与For Each循环结合使用

Excel VBA如果然后与For Each循环结合使用,excel,vba,Excel,Vba,有人能就以下几点提出建议吗 我用以下方式实现了这个For循环,但我需要添加另一个条件(“If”我想)(请参见注释): **'如果“A2:A1000”中的单元格为“cat”且不为空,则运行以下操作:** 对于范围内的每个cel(“D2:D1000”) 时间=细胞值 如果不是空的(时间),那么 “代码做了一些事情 如果结束 下一个 **'如果单元格位于“A2:A1000”“cat”中,但不是空白,则运行以下命令:** “一些代码 试试: 为每个嵌套?不确定,但工作不正常。我认为我以前的解决方案有效,

有人能就以下几点提出建议吗

我用以下方式实现了这个For循环,但我需要添加另一个条件(“If”我想)(请参见注释):

**'如果“A2:A1000”中的单元格为“cat”且不为空,则运行以下操作:**
对于范围内的每个cel(“D2:D1000”)
时间=细胞值
如果不是空的(时间),那么
“代码做了一些事情
如果结束
下一个
**'如果单元格位于“A2:A1000”“cat”中,但不是空白,则运行以下命令:**
“一些代码
试试:


为每个嵌套?不确定,但工作不正常。我认为我以前的解决方案有效,但没有,我已经删除了它。
**'if cell in "A2:A1000" = "cat" and is not empty then run this:**

    For Each cel In .Range("D2:D1000") 
    
    Time = cel.Value
    If Not IsEmpty(Time) Then
    
    'code does some stuff
    
        End If
    Next

**'Else if cell in "A2:A1000" <> "cat" but not blank run this:**

'some code
Sub forfor()
        
Dim SrchRng As Range, celq As Range
Set SrchRng = Range("A1:A1000")
        
For Each celq In SrchRng
If InStr(1, celq.Value, "cat") > 0 Then
    
    For Each cel In .Range("D2:D1000") 
    Time = cel.Value
    If Not IsEmpty(Time) Then
    'code does some stuff
    End If
    Next

End If
Next celq
    
End Sub