Copy and paste from sheet to sheet based on matching criteria

Kemidan2014

Board Regular
Joined
Apr 4, 2022
Messages
229
Office Version
  1. 365
Platform
  1. Windows
I am trying to expand my complaint tracking sheet that we use to monitor and track status of complaints over time. I am OK with copy paste macros but i still cant wrap my mind around looking up and matching to paste data.

here is summary of what the sheet does from logic stand point

On open it references a master file that we download from customer website weekly and updates Sheet 1, this is done with macros.
Sheet 2 uses macro to clear contents of sheet 2, filter sheet 1 based on criteria and copy paste data from sheet 1 into sheet 2.
What we want to add new macro to append the data in sheet 1 FROM sheet 2 this time by adding columns of data on the side outside of what we get from customer and paste that information into the corresponding record into Sheet 1. right now we do this manually and its a pain because the records on sheet 1 is over 1000 but sheet 2 based on criteria usually has 20 so its easier to find and update on sheet 20 and throw it back to sheet 1

here is sheet 2
Customer Complaint Tracker.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1QIMS#Doc TypeRankSupplier CodePart NamePart NumberOverall StatusNCD DescriptionModelLT CM Plan DueOriginal LTCM Actual Due DateRevised LTCM Actual Due DateCloseInitial Issuance DateOfficial Issuance DateLTCM Plan SubmittedLTCM Plan Accepted DateLTCM Plan Rejection DateLTCM Actual SubmittedLTCM Actual Accepted DateLTCMActualRejectionDateNAMCAACT QEAMNEXT STEPSTARGET
214-01016-ZR-4093QIRB0101-6COVER ASSY, TIMING CHAIN W/WATER PUMP11310-0T180Officially Released, Awaiting LTCM PlanFOREIGN MATERIALZR4/19/223/31/224/4/22TMMWVBlake LaffertyChris<insert activity here>"date"
314-01016-ZR-4094QPRB0101-6COVER ASSY, TIMING CHAIN W/WATER PUMP11310-0T180Officially Released, Awaiting LTCM PlanCRACKEDZR4/19/224/1/224/4/22TMMWVBlake LaffertyChris
401-01016-T1-4027QPRB0101-6PUMP ASSY, OIL15100-F0011Officially Released, Awaiting LTCM PlanABNORMAL NOISET14/19/224/1/224/4/22TMMK-PWTMisty GatliffMike
514-01016-TNGA-4098QPRB0101-6PISTON13211-F0010Awaiting LTCM Plan Response Acceptance, LTCM Plan SubmittedEXCESS MATERIALTNGA4/12/224/22/223/23/223/28/224/14/22TMMWVAce StatonChris
AACT
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:V50Expression=ISBLANK($A2)textNO
A2:V50Expression=AND($J2<=TODAY(),$J2>=(TODAY()-5))textNO
A2:V50Expression=NOT(ISBLANK($M2))textNO
A2:V50Expression=$J2<=TODAY()textNO


Where column W X Y and Z is the data we want to copy using matching Complaint number in Column A

Here is sheet 1 destination
Customer Complaint Tracker.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1QIMS#Doc TypeRankSupplier CodePart NamePart NumberOverall StatusNCD DescriptionModelLT CM Plan DueOriginal LTCM Actual Due DateRevised LTCM Actual Due DateCloseInitial Issuance DateOfficial Issuance DateLTCM Plan SubmittedLTCM Plan Accepted DateLTCM Plan Rejection DateLTCM Actual SubmittedLTCM Actual Accepted DateLTCMActualRejectionDateNAMCAACT QEAMNEXT STEPSTARGET
201-01016-V6-4053QPRB0101-6COVER SUB-ASSY, CYLINDER HEAD, LH11202-0P011Closed-CancelledFIT CONDITIONV65/3/20214/28/2021TMMK-PWT
301-01016-V6-4054QPRB0101-6COVER SUB-ASSY, CYLINDER HEAD, RH11201-0P010Closed-CancelledLOOSEV65/3/20214/28/2021TMMK-PWT
401-01016-V6-4055QPRC0101-6COVER SUB-ASSY, CYLINDER HEAD, LH11202-0P040Closed-CancelledPOPPING / PULLING OUTV65/3/20214/28/2021TMMK-PWT
501-01016-V6-4086QPRB0101-6COVER ASSY, TIMING CHAIN11310-0P050Closed-CancelledWRONG PARTV63/8/20223/7/2022TMMK-PWT
60101-6-080-4004QPRB0101-6COVER ASSY, TIMING CHAIN11310-0V020Closed-CancelledSCRATCHES080Y,417W,434W,502W,511W,512W,537W,541W,567W,574W,9/25/20179/15/2016TMMAL
70101-6-116-4005QPRB0101-6COVER SUB-ASSY, CYLINDER HEAD, RH11201-0P010Closed - LTCM EffectiveMISSING PART116Y,118Y,614W,641W,663W,672W,676W,699W,705W,709W2/22/20173/10/20179/23/20171/30/20172/7/20172/28/20174/6/20174/18/2017TMMWV
Complaints
Cells with Data Validation
CellAllowCriteria
W2:W1048576List=Lists!$A$2:$A$14
X2:X1048576List=Lists!$C$2:$C$12
Y2:Y1048576List=Lists!$F$2:$F$11


again destination columns are W X Y Z but as you can see the complaint numbers in Sheet 1 are in a different order becuase we use filtering in Sheet 2 for easy tracking because once complaint is closed its just there for reference.

In the example the expectation is when i engage macro the information that we manually added Sheet 2 W2, X2, Y2, and Z2 will be copy and pasted into Sheet 1 W77, X77, Y77, and Z77 because thats where the record is in Sheet 1. this information can overwritten because for example the owner ship may change, the next step may change and the date may change we just dont want to alter data in any other columns.

i appreciate your knowledge!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Okay replace Sheet 2 with AACT and Sheet 1 with Complaints hah i didnt realize minisheets gave you this much detail
 
Upvote 0
This is code i have Cannibalized from else where in my workbook I feel like starting at "For Each c...." needs to change alot because this is basically trying to add new information and add it to the bottom, i test it but it doesnt error but it also doesnt do anything either...

VBA Code:
Private Sub Testcopy()
  Dim srcSH As Worksheet, desSH As Worksheet
  Dim i As Long, j As Long, nRow As Long, n As Long
  Dim rng As Range, col As Range, c As Range, f As Range
 
  Application.ScreenUpdating = False
  Sheets("Complaints").Unprotect Password:="Secret"
  Set srcSH = Workbooks("Customer Complaint Tracker test.xlsm").Sheets("AACT")
  Set desSH = Workbooks("Customer Complaint Tracker test.xlsm").Sheets("Complaints")
  Set rng = srcSH.Range("W:Z")
 
  For Each c In srcSH.Range("A2", srcSH.Range("A" & Rows.count).End(3))
    Set f = desSH.Range("A:A").Find(c.Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then nRow = f.Row Else nRow = desSH.Range("A" & Rows.count).End(3).Row + 1
    j = 0
    For Each col In rng.Columns
      n = col.Column
      j = j + 1
      desSH.Cells(nRow, j).Value = srcSH.Cells(c.Row, n).Value
    Next
  Next
  Sheets("Complaints").Protect Password:="Secret"
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
So someone showed me the magic of Record Macro button in developer tab which OMG im going to use this from now on however to answer my own question for the benefit of the forum I have attached the result that works.

VBA Code:
Sub Testfilter ()
'Make declarations
  Dim lookupsheet As Worksheet, updatesheet As Worksheet
  Dim valuetosearch As String
  Dim i As Integer, t As Integer
'Disable screen update and unprotect Complaints
  Application.ScreenUpdating = False
  Sheets("Complaints").Unprotect Password:="Secret"
 'Define a couple of the declarations
 Set lookupsheet = Worksheets("AACT")
 Set updatesheet = Worksheets("Complaints")
 
 'Look for last rows in both sheets
 lastrowlookup = lookupsheet.Range("A1").End(xlDown).Row
 lastrowupdate = updatesheet.Cells(Rows.Count, "A").End(xlUp).Row
 'Select last row in look up sheet
 Cells(lastrowlookup, 1).Select
 Dim searchrange As Range
 Set searchrange = Range(Cells(2, 1), Cells(lastrowlookup, 1))
 

'''''
'check for macro

  Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Range("A2").Select
ActiveCell.FormulaR1C1 = "=IF(COUNTIF(C[1],RC[1])>1,""Error"",""OK"")"
    Selection.AutoFill Destination:=Range("A2:A29")
    Range("A2:A29").Select
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "=COUNTIF(R[1]C:R[28]C,""Error"")"
    Range("A2").Select


If Range("A1").Value > 0 Then
    MsgBox ("You messed up")
    Else
    Columns("A:a").Delete
    End If

'filter for complaint
 updatesheet.Select
 Rows("1:1").Select
 Selection.AutoFilter
 lookupsheet.Select
Range("a1").Select
 counter = 0
 
 

 
 
 
 
 ''''looks for heading
      updatesheet.Select
    Rows("1:1").Select
    Selection.Find(What:="AACT QE", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
Dim begcolmpaste As Integer
 begcolmpaste = ActiveCell.Column
'''
 
 For Each cell In searchrange
 Dim searchcriteria As String
  lookupsheet.Select
 ActiveCell.Offset(1, 0).Select

  searchcriteria = ActiveCell.Value


 updatesheet.Select
 ActiveSheet.Range("$A:$AB").AutoFilter Field:=1, Criteria1:=searchcriteria
 lastrowlookup = updatesheet.Range("A1").End(xlDown).Row
 
 
lookupsheet.Select
ActiveCell.Offset(0, 22).Resize(RowSize:=1, ColumnSize:=4).Copy
updatesheet.Select

Range(Cells(lastrowlookup, begcolmpaste), Cells(lastrowlookup, begcolmpaste + 3)).Select
Selection.PasteSpecial Paste:=xlPasteValues
 


 counter = counter + 1
 Next
 'to take filter off after loop
   updatesheet.Select
 Rows("1:1").Select
 Selection.AutoFilter
 
  MsgBox ("Update Complete")
 
 
 
 'Enable Screen update and protect Complaints sheet
 
  Sheets("Complaints").Protect Password:="Secret"
  Application.ScreenUpdating = True
  End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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