[ACCEPTED]-How to check a variable if it have a value or not?-excel

Accepted answer
Score: 12

Depends what you are testing.

A range object 1 or a 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

More Related questions