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:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
How about
VBA Code:
    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
    Else
        MsgBox "No new employee records found"
    End If
 
Upvote 0
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 Else MsgBox "No new employee records found"
Thank worked a treat thank you very much.

Would there be a code that in the instance there are records copied across to the other sheet, that message popped up to say there were x amount of records copied across based on the amount of rows that were copied?
 
Upvote 0
How about
VBA Code:
    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 & " records copied"
    Else
        MsgBox "No new employee records found"
    End If
 
Upvote 0
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 & " records copied"
You are a legend, thank you again....I really appreciate your assistance.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Hello,

The code above only works to 50,000 rows....anything after this, there are errors. Do you know what is causing this? Thank you.
 
Upvote 0
The sheet/range that I have the code working from has around 55,000 rows of data (formulas), and when there are anything more than 50,000 rows, the code copies across 5001 rows, but 5000 rows are blank and one is an employee record. When I delete the 5000 rows worth of formulas to have only 50,000 rows of data, then the code works fine.
 
Upvote 0
...it also does not find then next blank row on the destination sheet and pastes some 5000 rows below.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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