Message Pop Up Box Query

CarlStephens

Board Regular
Joined
Sep 25, 2020
Messages
128
Office Version
  1. 2016
Platform
  1. Windows
Hello All,

In the below code highlighted bold, there is in column AQ a possibility that there could be a "Yes" in the cell. Is there a code to add to the below, that will say in addition to the " new employee records found" (in red below), that the code will also count the number of "Yes" cells and pop up in the same message box as "new employee records found"? Thank you.

With wsData.Rows(1)
.AutoFilter Field:=42, Criteria1:="Not On Joiners List"
.AutoFilter Field:=43, Criteria1:="<90"
If wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
wsData.Range("AR2:AU" & lr).SpecialCells(xlCellTypeVisible).Copy
wsDest.Range("AC" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues
wsDest.Select
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 1 & " new employee records were found."
Else
MsgBox "No new employee postings found."
End If
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Does this example help?

VBA Code:
 Range("C3").Value = WorksheetFunction.CountIf(Range("AQ:AQ"), "yes")
 
Upvote 0
Thank you for your reply. It kind of helps.

The below part of the code count in red counts how many rows were copied and pasted in the wsDest sheet, and after a message box appears (after pasting) saying how many rows were pasted across. What I need in the same message box, is to say how many rows have a "Yes" in them. Does that make sense, as I am not very good at explaining myself? Thank you again for your time.

With wsData.Rows(1)
.AutoFilter Field:=42, Criteria1:="Not On Joiners List"
.AutoFilter Field:=43, Criteria1:="<90"
If wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
wsData.Range("AR2:AU" & lr).SpecialCells(xlCellTypeVisible).Copy
wsDest.Range("AC" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues
wsDest.Select
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 1 & " new employee records were found."
 
Upvote 0
nemmi69's reply shows you how to to that calculation. So you can just add it to your current MsgBox, i.e.
VBA Code:
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 1 & " new employee records were found." & vbCrLf & _
    WorksheetFunction.CountIf(wsData.Range("AQ:AQ"), "yes") & " yes items"
 
Upvote 0
Solution
Thank you so much, that worked. I am a fairly newbie to VBA so still trying to pick it up. Thank you once again.
 
Upvote 0
You are welcome.

Since you are fairly new to VBA, I will let you in on a few key details of my last post.
- vbCrLf is how you do a carriage return/line feed in VBA. We wanted our message box to go to a second line, so we used that.
- Using space and underscore (" _") at the end of a line of VBA code is telling VBA that this particular command wraps and goes to another line. We could not use that, and just keep typing across, but sometimes that can make it had to read. So that is often used for readability sake. It is how you split a single command over multiple lines.
 
Upvote 0
That makes total sense now that you have put that, thank you. So, if I was to put a third line (and any subsequent lines), I would need to add & vbCrLf & _ at the end of each line? Something like the below?

MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 1 & " new employee record found." & vbCrLf & _
WorksheetFunction.CountIf(wsData.Range("AX:AX"), "yes") & " yes items." & vbCrLf & _
MsgBox "XYZ."
 
Upvote 0
That makes total sense now that you have put that, thank you. So, if I was to put a third line (and any subsequent lines), I would need to add & vbCrLf & _ at the end of each line? Something like the below?

MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 1 & " new employee record found." & vbCrLf & _
WorksheetFunction.CountIf(wsData.Range("AX:AX"), "yes") & " yes items." & vbCrLf & _
MsgBox "XYZ."
Not quite. Remember, the space/underscore means a continuation of the original command. There, you do NOT use the "MsgBox" command again (as it is just a continuation of the original), i.e.
VBA Code:
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 1 & " new employee record found." & vbCrLf & _
    WorksheetFunction.CountIf(wsData.Range("AX:AX"), "yes") & " yes items." & vbCrLf & _
    "XYZ."

Note that you do NOT need to do the continuation for the third line. Like I said, it is just for code readability. You could also do this and have the exact same results:
VBA Code:
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 1 & " new employee record found." & vbCrLf & _
    WorksheetFunction.CountIf(wsData.Range("AX:AX"), "yes") & " yes items." & vbCrLf & "XYZ."
 
Upvote 0
Of course, and thank you for clarifying that for me. If I wanted a space/row between each of the three lines, what would I need to add to the code?
 
Upvote 0
Of course, and thank you for clarifying that for me. If I wanted a space/row between each of the three lines, what would I need to add to the code?
Simply double up on the vbCrLf command (it makes sense logically, you are doing 2 carriage return line feeds, just like you would on any word processor or type-writer), i.e.
VBA Code:
... & vbCrLf & vbCrLf & ...
 
Upvote 0

Forum statistics

Threads
1,215,826
Messages
6,127,120
Members
449,359
Latest member
michael2

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