Message box to return values in cells

Godders199

Active Member
Joined
Mar 2, 2017
Messages
313
Office Version
  1. 2013
Hello, i have been looking for an example of VBA for a message box which returns values of cells where criteria is met. While i have found VBA which will return the cell range, i cannot find an example of displaying values.

here is an example of what i mean.

orderNameDate
1Pete
2bill13/11/2017
3james
4jim 13/11/2017

<tbody>
</tbody><colgroup><col><col><col></colgroup>

From the above table, I would require a message box to display the order number and name if the date is blank.

If anyone has an example of this VBA it would be appreciated.

Thanks
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try this:
Code:
Sub Check_Date()
Application.ScreenUpdating = False
Dim i As Long
Dim ans As String
Dim ss As String
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = Lastrow To 1 Step -1
        If Cells(i, "C").Value = "" Then ans = Cells(i, 1).Value & vbTab & Cells(i, 2).Value & vbNewLine & ans
        
    Next
ss = "These Dates Are Blank" & vbNewLine & "Order" & vbTab & "Name" & vbNewLine
MsgBox ss & ans
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Something like
Code:
Sub MsgList()

    Dim Cl As Range
    Dim Rng As Range
    Dim Msg As String
    
    For Each Rng In Columns(3).SpecialCells(xlBlanks).Areas
        If Rng.Count = 1 Then
            Msg = Msg & Rng.Offset(, -2) & " " & Rng.Offset(, -1) & vbLf
        Else
            For Each Cl In Rng
                Msg = Msg & Cl.Offset(, -2) & " " & Cl.Offset(, -1) & vbLf
            Next Cl
        End If
    Next Rng
    MsgBox Msg
    
End Sub
 
Upvote 0
Once again thank , you, what do i need to add to the code, so it only displays the message box when there are rows that meet the criteria?

Thanks
 
Upvote 0
Try this
Code:
Sub MsgList()

    Dim Cl As Range
    Dim Rng As Range
    Dim Msg As String
    
    For Each Rng In Columns(3).SpecialCells(xlBlanks).Areas
        If Rng.Count = 1 Then
            Msg = Msg & Rng.Offset(, -2) & " " & Rng.Offset(, -1) & vbLf
        Else
            For Each Cl In Rng
                Msg = Msg & Cl.Offset(, -2) & " " & Cl.Offset(, -1) & vbLf
            Next Cl
        End If
    Next Rng
    If Len(Msg) > 0 Then MsgBox Msg
    
End Sub
 
Upvote 0
My script should do exactly what you asked for.
But it's true if no rows meet the criteria you would get a message showing no value.
Try this:
If no rows meet your criteria you will get no message::

Code:
Application.ScreenUpdating = False
Dim i As Long
Dim ans As String
Dim ss As String
Dim Lastrow As Long
Dim x As Long
x = 1
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = Lastrow To 1 Step -1
        If Cells(i, "C").Value = "" Then ans = Cells(i, 1).Value & vbTab & Cells(i, 2).Value & vbNewLine & ans: x = x + 1
        
    Next
ss = "These Dates Are Blank" & vbNewLine & "Order" & vbTab & "Name" & vbNewLine
 If x > 1 Then MsgBox ss & ans
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,568
Members
449,237
Latest member
Chase S

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