Complex VBA to copy and paste based on 2 columns and different criteria

thedeadzeds

Active Member
Joined
Aug 16, 2011
Messages
451
Office Version
  1. 365
Platform
  1. Windows
Guys, not even sure if this is possible.

I have an excel table called 'Newport' which consists of the following 9 columns:


Dealer,
DecsR
Attempt - (this column will only consist of New, 1st, 2nd and 3rd)
RegNO,
Salute,
Updated,
Contdate,
Completecode


The table normally has around 2000 records. Is there a way to do the following:


Find The oldest 2 results based on 'Attempt' by each 'DescR' based on the oldest ContDate.

So out of the 2000 records copy 2 of each Attempt for each DescR to tab 'Blue'. If there is not 2 then copy what is there.

If this is possible, Is there a way to base the volume (ie 2 in this example) on whatever number is in cell a5 on the menu tab.


See expected results below: So in this we are showing the oldest New Calls based on contdate for Each DecsR, The oldest 1st based on contdate for Each DecsR, the oldest 3rd based on contdate for Each DecsR and so on

[TABLE="class: grid, width: 699"]
<tbody>[TR]
[TD="align: center"]Dealer[/TD]
[TD="align: center"]DescR[/TD]
[TD="align: center"]Attempt[/TD]
[TD="align: center"]RegNo[/TD]
[TD="align: center"]Salute[/TD]
[TD="align: center"]Updated[/TD]
[TD="align: center"]contdate[/TD]
[TD="align: center"]completecode[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE1[/TD]
[TD="align: center"]New Calls[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Mr Jones 1[/TD]
[TD="align: center"]01/01/2018[/TD]
[TD="align: center"]01/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE1[/TD]
[TD="align: center"]New Calls[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Mr Jones 2[/TD]
[TD="align: center"]02/01/2018[/TD]
[TD="align: center"]02/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE1[/TD]
[TD="align: center"]1st[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Mr Jones 3[/TD]
[TD="align: center"]03/01/2018[/TD]
[TD="align: center"]03/02/2018[/TD]
[TD="align: center"]TEA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE1[/TD]
[TD="align: center"]1st[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]Mr Jones 4[/TD]
[TD="align: center"]04/01/2018[/TD]
[TD="align: center"]04/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE1[/TD]
[TD="align: center"]2nd[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]Mr Jones 5[/TD]
[TD="align: center"]05/01/2018[/TD]
[TD="align: center"]05/02/2018[/TD]
[TD="align: center"]LMS[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE1[/TD]
[TD="align: center"]2nd[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]Mr Jones 6[/TD]
[TD="align: center"]06/01/2018[/TD]
[TD="align: center"]06/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE1[/TD]
[TD="align: center"]3rd[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]Mr Jones 7[/TD]
[TD="align: center"]07/01/2018[/TD]
[TD="align: center"]07/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE1[/TD]
[TD="align: center"]3rd[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]Mr Jones 8[/TD]
[TD="align: center"]08/01/2018[/TD]
[TD="align: center"]08/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE2[/TD]
[TD="align: center"]New Calls[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]Mr Jones 9[/TD]
[TD="align: center"]09/01/2018[/TD]
[TD="align: center"]09/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE2[/TD]
[TD="align: center"]New Calls[/TD]
[TD="align: center"]10[/TD]
[TD="align: center"]Mr Jones 10[/TD]
[TD="align: center"]10/01/2018[/TD]
[TD="align: center"]10/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE2[/TD]
[TD="align: center"]1st[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]Mr Jones 11[/TD]
[TD="align: center"]11/01/2018[/TD]
[TD="align: center"]11/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE2[/TD]
[TD="align: center"]1st[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]Mr Jones 12[/TD]
[TD="align: center"]12/01/2018[/TD]
[TD="align: center"]12/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE2[/TD]
[TD="align: center"]2nd[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]Mr Jones 13[/TD]
[TD="align: center"]13/01/2018[/TD]
[TD="align: center"]13/02/2018[/TD]
[TD="align: center"]LMS[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE2[/TD]
[TD="align: center"]2nd[/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]Mr Jones 14[/TD]
[TD="align: center"]14/01/2018[/TD]
[TD="align: center"]14/02/2018[/TD]
[TD="align: center"]LMS[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE2[/TD]
[TD="align: center"]3rd[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]Mr Jones 15[/TD]
[TD="align: center"]15/01/2018[/TD]
[TD="align: center"]15/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]SE2[/TD]
[TD="align: center"]3rd[/TD]
[TD="align: center"]16[/TD]
[TD="align: center"]Mr Jones 16[/TD]
[TD="align: center"]16/01/2018[/TD]
[TD="align: center"]16/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWB[/TD]
[TD="align: center"]New Calls[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]Mr Jones 17[/TD]
[TD="align: center"]17/01/2018[/TD]
[TD="align: center"]17/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWB[/TD]
[TD="align: center"]New Calls[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]Mr Jones 18[/TD]
[TD="align: center"]18/01/2018[/TD]
[TD="align: center"]18/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWB[/TD]
[TD="align: center"]1st[/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]Mr Jones 19[/TD]
[TD="align: center"]19/01/2018[/TD]
[TD="align: center"]19/02/2018[/TD]
[TD="align: center"]CCB[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWB[/TD]
[TD="align: center"]1st[/TD]
[TD="align: center"]20[/TD]
[TD="align: center"]Mr Jones 20[/TD]
[TD="align: center"]20/01/2018[/TD]
[TD="align: center"]20/02/2018[/TD]
[TD="align: center"]LMS[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWB[/TD]
[TD="align: center"]2nd[/TD]
[TD="align: center"]21[/TD]
[TD="align: center"]Mr Jones 21[/TD]
[TD="align: center"]21/01/2018[/TD]
[TD="align: center"]21/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWB[/TD]
[TD="align: center"]2nd[/TD]
[TD="align: center"]22[/TD]
[TD="align: center"]Mr Jones 22[/TD]
[TD="align: center"]22/01/2018[/TD]
[TD="align: center"]22/02/2018[/TD]
[TD="align: center"]LMS[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWB[/TD]
[TD="align: center"]3rd[/TD]
[TD="align: center"]23[/TD]
[TD="align: center"]Mr Jones 23[/TD]
[TD="align: center"]23/01/2018[/TD]
[TD="align: center"]23/02/2018[/TD]
[TD="align: center"]LMS[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWB[/TD]
[TD="align: center"]3rd[/TD]
[TD="align: center"]24[/TD]
[TD="align: center"]Mr Jones 24[/TD]
[TD="align: center"]24/01/2018[/TD]
[TD="align: center"]24/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWS[/TD]
[TD="align: center"]New Calls[/TD]
[TD="align: center"]25[/TD]
[TD="align: center"]Mr Jones 25[/TD]
[TD="align: center"]25/01/2018[/TD]
[TD="align: center"]25/02/2018[/TD]
[TD="align: center"]CCB[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWS[/TD]
[TD="align: center"]New Calls[/TD]
[TD="align: center"]26[/TD]
[TD="align: center"]Mr Jones 26[/TD]
[TD="align: center"]26/01/2018[/TD]
[TD="align: center"]26/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWS[/TD]
[TD="align: center"]1st[/TD]
[TD="align: center"]27[/TD]
[TD="align: center"]Mr Jones 27[/TD]
[TD="align: center"]27/01/2018[/TD]
[TD="align: center"]27/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWS[/TD]
[TD="align: center"]1st[/TD]
[TD="align: center"]28[/TD]
[TD="align: center"]Mr Jones 28[/TD]
[TD="align: center"]28/01/2018[/TD]
[TD="align: center"]28/02/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWS[/TD]
[TD="align: center"]2nd[/TD]
[TD="align: center"]29[/TD]
[TD="align: center"]Mr Jones 29[/TD]
[TD="align: center"]29/01/2018[/TD]
[TD="align: center"]01/03/2018[/TD]
[TD="align: center"]LMS[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWS[/TD]
[TD="align: center"]2nd[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]Mr Jones 30[/TD]
[TD="align: center"]30/01/2018[/TD]
[TD="align: center"]02/03/2018[/TD]
[TD="align: center"]LMS[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWS[/TD]
[TD="align: center"]3rd[/TD]
[TD="align: center"]31[/TD]
[TD="align: center"]Mr Jones 31[/TD]
[TD="align: center"]31/01/2018[/TD]
[TD="align: center"]03/03/2018[/TD]
[TD="align: center"]LMS[/TD]
[/TR]
[TR]
[TD="align: center"]BAA[/TD]
[TD="align: center"]PWS[/TD]
[TD="align: center"]3rd[/TD]
[TD="align: center"]32[/TD]
[TD="align: center"]Mr Jones 32[/TD]
[TD="align: center"]01/02/2018[/TD]
[TD="align: center"]04/03/2018[/TD]
[TD="align: center"]CUA[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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