How to check for nulls in a selection of multiple cells?

aceizbad

New Member
Joined
Jan 9, 2019
Messages
1
Hi guys,

Newbie here!

So I'm in the process of automating some tasks at work and am really new to VBA.

I have a VBA code that finds a column header and then selects the data underneath this header upto the last row.
From here I want to create an If statement to see whether the selection equals to zero. If it does, then I want to show a message box.

Code:
Sub Checkblank()

Call IfBlank


Dim rng As Range


Set rng = Selection


If IsNull(rng) = True Then


MsgBox "No data for country selected"


End If


End Sub

Code:
Sub IfBlank()


Dim source As Range
Dim cl As Range
Dim Mnth As String
Mnth = InputBox("Enter Year & Month as MMM_YYYY")




Set source = Selection


With ActiveSheet.Cells
    Set cl = .Find(Mnth, After:=.Range("A1"), LookIn:=xlValues, LookAt:=xlWhole)
    If Not cl Is Nothing Then
        cl.Select
        End If
    End With
    ActiveCell.Offset(1, 0).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.SpecialCells(xlCellTypeVisible).Select
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top