How to check a variable if it matters or not?

I have a variable that contains the range value that is selected by the user.

How to check if it matters or not?

I tried these:

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

But they are only good when the variable contains data, such as text or numbers or spaces.

Any idea?

+4
source share
1 answer

Depends on what you are testing.

Range object or cell value?

 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 
+10
source

All Articles