Checking Duplication before pasting the data or POP UP before pasting the data

shahzeb123

Board Regular
Joined
Jul 29, 2021
Messages
61
Office Version
  1. 2016
Platform
  1. Windows
I am using below code to copy data from one sheet to another. What i need is that before pasting there should be a pop up to say yes or no or it should check the duplication before pasting the data.

VBA Code:
Dim R&
        R = Sheet6.Cells(Rows.Count, 2).End(xlUp)(2).Row
        Sheet6.Cells(R, 12).Value = Sheet1.[F24].Value
        Sheet6.Cells(R, 2).Value = Sheet1.[D14].Value
        Sheet6.Cells(R, 3).Value = Sheet1.[D15].Value
        Sheet6.Cells(R, 4).Value = Sheet1.[D16].Value
        Sheet6.Cells(R, 5).Value = Sheet1.[D20].Value
        Sheet6.Cells(R, 5).Value = Sheet1.[D20].Value
        Sheet6.Cells(R, 6).Value = Sheet1.[D21].Value
        Sheet6.Cells(R, 7).Value = Sheet1.[M1].Value
        Sheet6.Cells(R, 8).Value = Sheet1.[D5].Value
        Sheet6.Cells(R, 9).Value = Sheet1.[G15].Value
        Sheet6.Cells(R, 10).Value = Sheet1.[G16].Value
        Sheet6.Cells(R, 11).Value = Sheet1.[G19].Value
        Sheet6.Cells(R, 13).Value = Sheet1.[G43].Value
        Sheet6.Cells(R, 14).Value = Sheet1.[G44].Value
        Sheet6.Cells(R, 15).Value = Sheet1.[G45].Value
        Sheet6.Cells(R, 16).Value = Sheet1.[G46].Value
        Sheet6.Cells(R, 17).Value = Sheet1.[D35].Value
 
I would like to accomplish the same but I do not need a yes/no pop up, I simply want to check if the value is already listed in the range, and if so, pop up message saying "Associate already assigned".

This would be the instruction:
VBA Code:
Sub test()
  Dim R&
  Dim f As Range
  
  With Sheet6
    Set f = .Range("B:B").Find(Sheet1.[D14].Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      MsgBox "Associate already assigned"
      Exit Sub
    End If
    R = .Cells(Rows.Count, 2).End(xlUp)(2).Row
    .Cells(R, 1).Value = Format(R - 1, "000") & "/FID/SUMB"
    .Cells(R, 12).Value = Sheet1.[F24].Value
    .Cells(R, 2).Value = Sheet1.[D14].Value
'...
  End With
End Sub

To review the code you must paste the code here using code tag.
But the meaning of your question is different from this thread. I recommend you create a new thread.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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