Synch combinations of old and new data

ellison

Active Member
Joined
Aug 1, 2012
Messages
336
Office Version
  1. 365
Platform
  1. Windows
Morning all,

I'm trying to synch some new data into some old data and am wondering if there is a better way of doing this than my method which is held together by sheer good will (&frustration!)
Our Old Data is laid out like this:
LineIDColour1Condition1Colour2Condition3Colour3Condition3
2browngood
3redaverageorangeawful
4brownblackexcellent
5brown and red
Our Updated Data looks like this:

(Sometimes the data needs to be added in, but sometimes it's already on there).

Line IDColourConditionnotes (wouln't be on the actual data, just to help explain here...!)
3orangeawfulOrange is already on Line ID 3, no need to add
3whiteexcellentColour & condition would need to be added to Line ID 3
4brownawfulAlthough colour is already on Line ID 4, the "awful" would need to be added
4whiteWhite would need to be added in to Colour 3 on line ID 4
5brownexcellentAdd the new updated colour and condition to Line ID 5
All in all, the results should hopefully look something like this... wonder if somebody could help??


Huge thanks!

Line IDColour1Condition1Colour2Condition2Colour3Condition3Colour4Condition4
2browngood
3redaverageorangeawfulwhiteexcellent
4brownawfulblackexcellentwhite
5brown and redbrownexcellent
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try this:
The old data is in the activesheet, the updated data is in "sheet2".
VBA Code:
Sub a1116625a()
'https://www.mrexcel.com/board/threads/synch-combinations-of-old-and-new-data.1116625/
Dim i As Long, rc As Long
Dim va, k, j

Application.ScreenUpdating = False
    With Sheets("Sheet2")
    va = .Range("A2:C" & .Cells(Rows.count, "A").End(xlUp).Row)
    End With

For i = 1 To UBound(va, 1)
    
    k = Application.Match(va(i, 1), Range("A:A"), 0) 'row
    j = Application.Match(va(i, 2), Rows(k), 0) 'column
    If IsNumeric(j) Then
        Cells(k, j) = va(i, 2)
        Cells(k, j + 1) = va(i, 3)
    Else
        rc = Cells(k, Columns.count).End(xlToLeft).Column
        If rc Mod 2 = 0 Then rc = rc + 1
        Cells(k, rc + 1) = va(i, 2)
        Cells(k, rc + 2) = va(i, 3)
    End If

Next

Application.ScreenUpdating = True

End Sub
The result:
Book1
ABCDEFGHI
1LineIDColour1Condition1Colour2Condition3Colour3Condition3Colour4Condition4
22browngood
33redaverageorangeawfulwhiteexcellent
44brownawfulblackexcellentwhite
55brown and redbrownexcellent
Sheet1
 
Upvote 0
Thanks ever so much for your help.... I think I may be doing something wrong!

I've put the old Data in A1: H5
I put the Updated Info in A9:A14
I entered the code as a module (alt F11 etc)
I created sheet 2 and left it blank
Then I pressed Alt f8


And up popped an error message:

"run time error 13: type mismatch
and the debugger highlighted this line of code:

j = Application.Match(va(i, 2), Rows(k), 0) 'column


(also if I don't create sheet 2, I get a different error message:

Runtime error 9: subscript out of range
and the debugger highlights this bit of code:
j = Application.Match(va(i, 2), Rows(k), 0) 'column

Have I placed my data in the wrong locations maybe??
 
Upvote 0
The updated data must be in "sheet2" not "sheet 2", start at cel A1:
Book1
ABC
1Line IDColourCondition
23orangeawful
33whiteexcellent
44brownawful
54white
65brownexcellent
Sheet2


The old data is in different sheet, say "sheet1", it must be the active sheet when you run the code.
Book1
ABCDEFG
1LineIDColour1Condition1Colour2Condition3Colour3Condition3
22browngood
33redaverageorangeawful
44brownblackexcellent
55brown and red
Sheet1
 
Upvote 0
That's absolutely AMAZING!!! thank you so very much indeed!!!!!
 
Upvote 0
You're welcome, glad to help, & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,727
Members
448,294
Latest member
jmjmjmjmjmjm

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