如何检查variables是否有值?

我有一个variables,其中包含用户select的范围值。

我怎样才能检查它是否有价值?

我试过这些:

If variable_name.Value = Empty then .... If variable_name.Value = " " then ... 

但是,这些只有当variables包含文本或数字或空白的数据时才是好的。

任何想法?

取决于你正在testing的东西。

范围对象或单元格值?

 Sub test() Dim rngObject As Range Dim value As Variant Set rngObject = Sheet1.Range("A1:D5") If Not rngObject Is Nothing Then 'If not nothing then run this code End If value = rngObject.Cells(1, 1).value If Not IsEmpty(value) Then 'if Not empty then run this code End If If value <> vbNullString Then 'if value is not nullstring then run this code End If End Sub