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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
How do you know if there is a duplicate, that is, in which column it should be checked?
And if the duplicate exists, what should the code do?
 
Upvote 0
D14 should be checked whether it is the duplicate or not.

If it is duplicate then pop up should be generated to ask whether to add or not
 
Upvote 0
Try this:

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
      If MsgBox("Add or not?", vbQuestion + vbYesNo, "DUPLICATION") = vbNo Then
        Exit Sub
      End If
    End If
    R = .Cells(Rows.Count, 2).End(xlUp)(2).Row
    .Cells(R, 12).Value = Sheet1.[F24].Value
    .Cells(R, 2).Value = Sheet1.[D14].Value
    .Cells(R, 3).Value = Sheet1.[D15].Value
    .Cells(R, 4).Value = Sheet1.[D16].Value
    .Cells(R, 5).Value = Sheet1.[D20].Value
    .Cells(R, 5).Value = Sheet1.[D20].Value
    .Cells(R, 6).Value = Sheet1.[D21].Value
    .Cells(R, 7).Value = Sheet1.[M1].Value
    .Cells(R, 8).Value = Sheet1.[D5].Value
    .Cells(R, 9).Value = Sheet1.[G15].Value
    .Cells(R, 10).Value = Sheet1.[G16].Value
    .Cells(R, 11).Value = Sheet1.[G19].Value
    .Cells(R, 13).Value = Sheet1.[G43].Value
    .Cells(R, 14).Value = Sheet1.[G44].Value
    .Cells(R, 15).Value = Sheet1.[G45].Value
    .Cells(R, 16).Value = Sheet1.[G46].Value
    .Cells(R, 17).Value = Sheet1.[D35].Value
  End With
End Sub
 
Upvote 0
Solution
It works great !!

Thank you so much for your valuable response. Much appreciated.
 
Upvote 0
needed a little more help on the same thing if u are able to respond so please.

What i want is to start my specific code as well in this. i.e when I click on it, it should paste "001/FID/SUMB" on A coulmn and it goes on "002/FID/SUMB' and so on
 
Upvote 0
Try this:

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
      If MsgBox("Add or not?", vbQuestion + vbYesNo, "DUPLICATION") = vbNo Then
        Exit Sub
      End If
    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
    .Cells(R, 3).Value = Sheet1.[D15].Value
    .Cells(R, 4).Value = Sheet1.[D16].Value
    .Cells(R, 5).Value = Sheet1.[D20].Value
    .Cells(R, 5).Value = Sheet1.[D20].Value
    .Cells(R, 6).Value = Sheet1.[D21].Value
    .Cells(R, 7).Value = Sheet1.[M1].Value
    .Cells(R, 8).Value = Sheet1.[D5].Value
    .Cells(R, 9).Value = Sheet1.[G15].Value
    .Cells(R, 10).Value = Sheet1.[G16].Value
    .Cells(R, 11).Value = Sheet1.[G19].Value
    .Cells(R, 13).Value = Sheet1.[G43].Value
    .Cells(R, 14).Value = Sheet1.[G44].Value
    .Cells(R, 15).Value = Sheet1.[G45].Value
    .Cells(R, 16).Value = Sheet1.[G46].Value
    .Cells(R, 17).Value = Sheet1.[D35].Value
  End With
End Sub
 
Upvote 0
Hi Dante, would be be able to assist me with a similar task? 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". Also, if you have any tips on how to optimize my current code, that you be great too :)
 

Attachments

  • Indirect Tab.PNG
    Indirect Tab.PNG
    16.2 KB · Views: 6
  • Indirect_Code.PNG
    Indirect_Code.PNG
    119.1 KB · Views: 6
Upvote 0

Forum statistics

Threads
1,215,143
Messages
6,123,282
Members
449,094
Latest member
GoToLeep

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