IsEmpty VBA

ireland87

Board Regular
Joined
Jul 22, 2015
Messages
52
hello

I'm looking at a scenario such as the below;

I've defined names;
A2:A6 = System
B2:B6 = OpenTime
C2:C6 = Checked

The current time is 08:15

I would like to perform an "EmptyCheck" based on the time (08:00) but ignoring empty cells whereby the check would be completed after 08:00 i.e. the one at 08:30.
Then return a message box stating which system hasn't opened. For this example I would like it to return "system B"

SystemTimeChecked
A08:00Yes
B
08:00
C07:00Yes
D08:00Yes
E08:30

<tbody>
</tbody>

This code wellsr.com almost does what I need but I can't adapt it correctly.

Code:
[COLOR=inherit][FONT=Monaco][B]Sub[/B][/FONT][/COLOR][COLOR=inherit][FONT=Monaco] [/FONT][/COLOR][COLOR=#990000][FONT=Monaco][B]IsEmptyRange[/B][/FONT][/COLOR][COLOR=inherit][FONT=Monaco]()[/FONT][/COLOR]<code class="language-vb" data-lang="vb" style="box-sizing: border-box; font-size: inherit; border: 0px; border-radius: 0px; background-color: transparent; padding: 0px; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; color: inherit; white-space: pre;">[B]Dim[/B] [COLOR=#008080]cell[/COLOR] [B]As[/B] Range
[B]Dim[/B] [COLOR=#008080]bIsEmpty[/COLOR] [B]As[/B] [COLOR=#445588][B]Boolean[/B][/COLOR]

bIsEmpty [B]=[/B] [B]False[/B]
[B]For[/B] [B]Each[/B] cell [B]In[/B] Range([COLOR=#DD1144]"A1:B5"[/COLOR])
    [B]If[/B] IsEmpty(cell) [B]=[/B] [B]True[/B] [B]Then[/B]
        [COLOR=#999988][I]'An empty cell was found. Exit loop[/I][/COLOR]
        bIsEmpty [B]=[/B] [B]True[/B]
        [B]Exit[/B] [B]For[/B]
    [B]End[/B] [B]If[/B]
[B]Next[/B] cell

[B]If[/B] bIsEmpty [B]=[/B] [B]True[/B] [B]Then[/B]
    [COLOR=#999988][I]'There are empty cells in your range[/I][/COLOR]
    [COLOR=#999988][I]'**PLACE CODE HERE**[/I][/COLOR]
    MsgBox [COLOR=#DD1144]"There are empty cells in your range"[/COLOR]
[B]Else[/B]
    [COLOR=#999988][I]'There are NO empty cells in your range[/I][/COLOR]
    [COLOR=#999988][I]'**PLACE CODE HERE**[/I][/COLOR]
    MsgBox [COLOR=#DD1144]"All cells have values!"[/COLOR]
[B]End[/B] [B]If[/B] </code>[COLOR=inherit][FONT=Monaco][B]End[/B][/FONT][/COLOR][COLOR=inherit][FONT=Monaco] [/FONT][/COLOR][COLOR=inherit][FONT=Monaco][B]Sub[/B][/FONT][/COLOR]

Anyone able to help me out?

Then I can have this;

Code:
Sub mytimer()Application.OnTime TimeValue("08:15:00"), "EmptyCheck"
End Sub

Which will then go into this;
Code:
Private Sub Workbook_Open()mytimer
End Sub
 
Try this

Code:
Sub System_Check()
    Dim cell As Range, c As Range, cad As String
    
    On Error Resume Next
    Set cell = Range("C2:C6").SpecialCells(xlCellTypeBlanks)
    On Error GoTo 0
    If Not cell Is Nothing Then
        For Each c In cell
            cad = cad & c.Offset(, -2) & ", "
        Next
    End If
    If cad <> "" Then
        MsgBox "Systems Closed : " & Left(cad, Len(cad) - 2)
    Else
        MsgBox "all checked"
    End If
End Sub
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Many thanks Dante - that works a treat.

Try this

Code:
Sub System_Check()
    Dim cell As Range, c As Range, cad As String
    
    On Error Resume Next
    Set cell = Range("C2:C6").SpecialCells(xlCellTypeBlanks)
    On Error GoTo 0
    If Not cell Is Nothing Then
        For Each c In cell
            cad = cad & c.Offset(, -2) & ", "
        Next
    End If
    If cad <> "" Then
        MsgBox "Systems Closed : " & Left(cad, Len(cad) - 2)
    Else
        MsgBox "all checked"
    End If
End Sub
 
Upvote 0
is there any way I can paste the result into a single cell on a worksheet?
rather than the result appearing in the msgbox

Code:
[COLOR=#333333][I]    If cad <> "" Then
[/I][/COLOR][COLOR=#333333][I]        MsgBox "Systems Closed : " & Left(cad, Len(cad) - 2)[/I][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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