'This sub checks if the range has been set.
Sub RangeSet()
Dim TheRange As Range
If Not TheRange Is Nothing Then
Else
MsgBox "Before Setting the Range"
Set TheRange = Range("A1")
End If
If Not TheRange Is Nothing Then
MsgBox "After the range is set. TheRange = " & TheRange.Address
End If
End Sub
'This sub checks to see if an existing range contains any data.
Sub RangeEmpty()
Dim TheRangeNonEmpty As Range, TheRangeEmpty As Range
Dim loop_break As Boolean
Dim rw As Long, col As Integer, rwCtr As Long, colCtr As Integer
wsName = ActiveSheet.Name
Worksheets(wsName).Cells(1, 1) = "Not Empty"
Set TheRangeNonEmpty = Range("A1:A2")
Set TheRangeEmpty = Range("b1:b2")
loop_break = False
rw = TheRangeEmpty.Rows.Count
col = TheRangeEmpty.Columns.Count
rwCtr = 0
colCtr = 0
Do
rwCtr = rwCtr + 1
Do
colCtr = colCtr + 1
If TheRangeEmpty.Cells(rwCtr, colCtr) <> "" Then
loop_break = True
End If
Loop While loop_break = False And colCtr < col
Loop While loop_break = False And rwCtr < rw
TheRangeEmpty.Activate
If rwCtr = rw And colCtr = col Then
MsgBox "TheRangeEmpty is empty"
Else
MsgBox "TheRangeEmpty is non-empty"
End If
rwCtr = 0
colCtr = 0
Do
rwCtr = rwCtr + 1
Do
colCtr = colCtr + 1
If TheRangeNonEmpty.Cells(rwCtr, colCtr) <> "" Then
loop_break = True
End If
Loop While loop_break = False And colCtr < col
Loop While loop_break = False And rwCtr < rw
TheRangeNonEmpty.Activate
If rwCtr = rw And colCtr = col Then
MsgBox "TheRangeNonEmpty is empty"
Else
MsgBox "TheRangeNonEmpty is non-empty"
End If
End Sub