Option Explicit
Function xlIsBlank(TargetRange As Range) As Boolean
'
'****************************************************************************************
' Title xlIsBlank
' Target Application: MS Excel
' Function tests for any data in the target range
' if no data found, then xlIsBlank = True
' if data found in any cell in the range, then xlIsBLank = False
' Limitations: NONE
' Passed Values: TargetRange
'
'****************************************************************************************
'
'
Dim DataCol As Long
'
' test the first cell and, if blank, then test all remaining cells
' if any have data, set xlIsBlank to False, else set to True
'
With TargetRange
If Trim(.Cells(1)) <> "" Then
xlIsBlank = False
Exit Function
End If
On Error Resume Next
DataCol = .Cells.Find("*", .Cells(1), xlFormulas, _
xlWhole, xlByColumns, xlPrevious).Column
If Err <> 0 Then DataCol = 0
End With
If DataCol = 0 Then
xlIsBlank = True
Else
xlIsBlank = False
End If
End Function
Sub xlIsBlank_Test()
'
'****************************************************************************************
' Title xlIsBlank_Test
' Target Application: MS Excel
' Function demos xlIsBlank function
' Limitations: NONE
' Passed Values: None
'
'****************************************************************************************
'
'
MsgBox "return from IsEmpty for the current selection is " & _
vbCrLf & vbTab & vbTab & IsEmpty(Selection) & vbCrLf & vbCrLf & _
"return from IsNull for the current selection is " & _
vbCrLf & vbTab & vbTab & IsNull(Selection) & vbCrLf & vbCrLf & _
"return from xlIsBlank for the current selection is " & _
vbCrLf & vbTab & vbTab & xlIsBlank(Selection)
End Sub
|