Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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按钮中的空单元格,并在不为空时打开_Excel_Vba - Fatal编程技术网

Excel 我需要跳过vba按钮中的空单元格,并在不为空时打开

Excel 我需要跳过vba按钮中的空单元格,并在不为空时打开,excel,vba,Excel,Vba,我有一个按钮,每当我点击它时,它就会打开一个链接查询,但是有时候我查询中的一个字段是空的,我需要我的代码继续运行并跳过空单元格,我如何解决这个问题 我已经试过了,但没有达到预期的效果。VBA世界对我来说是一个全新的世界,所以如果你发现任何愚蠢的错误或者没有优化的方法,请警告我。下面的代码来自我试图跳过空单元格之前 Private Sub CommandButton1_Click() Dim SelecRng As Range Set SelecRng = ("F3:F44")

我有一个按钮,每当我点击它时,它就会打开一个链接查询,但是有时候我查询中的一个字段是空的,我需要我的代码继续运行并跳过空单元格,我如何解决这个问题

我已经试过了,但没有达到预期的效果。VBA世界对我来说是一个全新的世界,所以如果你发现任何愚蠢的错误或者没有优化的方法,请警告我。下面的代码来自我试图跳过空单元格之前

Private Sub CommandButton1_Click()
    Dim SelecRng As Range

    Set SelecRng = ("F3:F44")

    Each Cell In SelecRng
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run (Cell)
    Next
End Sub

每当我试图打开一些链接时,我不想看到错误。Tim Stack提供了一个很好的答案,但是我建议使用=vbNullString而不是=,运行检查,并使用Cell.value2而不是Cell.value

Private Sub CommandButton1_Click()
Dim SelecRng As Range

Set SelecRng = ("F3:F44") 'I would add a reference to the WB and WS here. Now it always refers to the active WB & WS

For Each Cell In SelecRng
If not Cell.Value = "" Then
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run (Cell.Value)
End If
Next
End Sub
在这个确切的例子中,这并不重要,但在其他一些情况下,它可能会;所以最好现在就养成这个习惯

这将是:

Private Sub CommandButton1_Click()
Dim SelecRng As Range

    Set SelecRng = ("F3:F44") 'I would add a reference to the WB and WS here. Now it always refers to the active WB & WS

    For Each Cell In SelecRng
        If Cell.Value2 <> vbNullString Then
            Set objShell = CreateObject("Wscript.Shell")
            objShell.Run (Cell.Value2)
        End If
    Next

End Sub

谢谢,我穿起来很合身