Message Pop Up

CarlStephens

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

I have the below code that basically searches for required information on one sheet and then pastes it onto another sheet when it finds it, however, there arent always new information to paste across and I am wondering whether there is a code to add to the below that when there is no new information to copy and paste across that a message box will appear to say "No new employee records found" - is this possible? Thank you.

VBA Code:
Sub CoypFilteredData()

Dim wsData      As Worksheet
Dim wsDest      As Worksheet
Dim lr          As Long

Application.ScreenUpdating = False

Set wsData = Worksheets("1. MAPS List")
Set wsDest = Worksheets("2. Joiners List")

wsData.Unprotect ("ML")


lr = wsData.Cells(Rows.Count, "AP").End(xlUp).Row

If wsData.FilterMode Then wsData.ShowAllData

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
    End If
    .AutoFilter Field:=42
    .AutoFilter Field:=43
    Range("AP1").Select
wsData.EnableAutoFilter = True
wsData.Protect Password:="ML", UserInterfaceOnly:=True
End With
Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:
If it's not finding the last row correctly on the destination sheet, it means you have data/formula in col AC below what you think is the last row.
Does it filter the data correctly?
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
It filters correctly on the wsData tab....but when I look at the area that the code has copied, I see that it has copied blank rows.
 
Upvote 0
In that case check that the variable lr is correctly finding the last row.
 
Upvote 0
Thank you for all your advice, I think it is fixed now.

Last query, and I will leave you alone I promise lol. 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 possible that will say in addition to the new employee records found (in red below), that code will count the number of "Yes" and pop up in the same message box as "new employee records found"?

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
 
Upvote 0
As this is a different question, you will need to start a new thread. Thanks
 
Upvote 0
Will do, and thank you again, your support has saved me so much time....it is appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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