2014-06-18 20 views
0

我一直在試圖檢查兩個單元格是否爲空。我知道如何檢查一個單元格,但我無法弄清楚如何檢查兩個單獨的單元格。這是我嘗試過的方式之一。當我運行它時,它將只檢查F17,但不檢查F12,如果我切換數字,它將只檢查F12。我感謝任何幫助。謝謝檢查VBA中的兩個空單元格

Sub Button11VerifyFilePathPresent_Click() 
Dim rCell As Range 

On Error GoTo ErrorHandle 
Set rCell = Range("F17", "F12") 

If IsEmpty(rCell) Then 
    MsgBox "Please select the files" ' "Cell " & rCell.Address & " is empty." 
End If 

BeforeExit: 
Set rCell = Nothing 
Exit Sub 
ErrorHandle: 
MsgBox Err.Description & " Error in procedure CellCheck." 
Resume BeforeExit 

End Sub 
+2

爲什麼不只是'如果IsEmpty(範圍(「F17」))和IsEmpty(範圍(「F12」))然後' – Sky

+0

其實它的工作,我忘了改變範圍變量。謝謝。 –

回答

1

考慮:

If Range("F17") & Range("F12") = "" Then 

如果級聯爲空,那麼他們都必須爲空。

+0

謝謝你的幫助。 –