Hi
Each week my company receives an exported orders spreadsheet from SAP. Basically I want to run a formula that will check if data exists in the existing orders spreadsheet, but i need the entire row to match, if one cell changes I would like it to change in the existing data. If data does not exist I would like it to add to the bottom.
Each customer has multiple orders and multiple products within, so with the code below from another forum, it would only return 1 line per customer instead of each order & material per customer.
I tried changing For Each Cl In Sws.Range("A2", Sws.Range("A" & Rows.Count).End(xlUp)) to say ("A:P" ... and also ("A" & "D" & "I" ... but neither of these alternatives worked.
FYI all blanks have been removed from the new data, and each customer is listed alongside it's corresponding orders and materials.
Sub UpdateData()
Dim Cl As Range
Dim Itm As Variant
Dim Dws As Worksheet
Dim Sws As Worksheet
Set Dws = Sheets("Data")
Set Sws = Sheets("New Data")
With CreateObject("scripting.dictionary")
For Each Cl In Sws.Range("A2", Sws.Range("A" & Rows.Count).End(xlUp))
If Not .exists(Cl.Value) Then .Add Cl.Value, Array(Cl.Offset(, 17).Value, Cl.Resize(, 18))
Next Cl
For Each Cl In Dws.Range("A2", Dws.Range("A" & Rows.Count).End(xlUp))
If .exists(Cl.Value) Then
If Not Cl.Offset(, 17).Value = .Item(Cl.Value)(0) Then
Cl.Resize(, 18).Value = .Item(Cl.Value)(1).Value
End If
.Remove Cl.Value
End If
Next Cl
If Not .Count > 0 Then Exit Sub
For Each Itm In .items
Dws.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(, 18).Value = Itm(1).Value
Next Itm
End With
End Sub
Thank you for your help in advance!
Each week my company receives an exported orders spreadsheet from SAP. Basically I want to run a formula that will check if data exists in the existing orders spreadsheet, but i need the entire row to match, if one cell changes I would like it to change in the existing data. If data does not exist I would like it to add to the bottom.
Each customer has multiple orders and multiple products within, so with the code below from another forum, it would only return 1 line per customer instead of each order & material per customer.
I tried changing For Each Cl In Sws.Range("A2", Sws.Range("A" & Rows.Count).End(xlUp)) to say ("A:P" ... and also ("A" & "D" & "I" ... but neither of these alternatives worked.
FYI all blanks have been removed from the new data, and each customer is listed alongside it's corresponding orders and materials.
Sub UpdateData()
Dim Cl As Range
Dim Itm As Variant
Dim Dws As Worksheet
Dim Sws As Worksheet
Set Dws = Sheets("Data")
Set Sws = Sheets("New Data")
With CreateObject("scripting.dictionary")
For Each Cl In Sws.Range("A2", Sws.Range("A" & Rows.Count).End(xlUp))
If Not .exists(Cl.Value) Then .Add Cl.Value, Array(Cl.Offset(, 17).Value, Cl.Resize(, 18))
Next Cl
For Each Cl In Dws.Range("A2", Dws.Range("A" & Rows.Count).End(xlUp))
If .exists(Cl.Value) Then
If Not Cl.Offset(, 17).Value = .Item(Cl.Value)(0) Then
Cl.Resize(, 18).Value = .Item(Cl.Value)(1).Value
End If
.Remove Cl.Value
End If
Next Cl
If Not .Count > 0 Then Exit Sub
For Each Itm In .items
Dws.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(, 18).Value = Itm(1).Value
Next Itm
End With
End Sub
Thank you for your help in advance!