Mess which could be helped with some lovely helper columns / macros maybe?!

ellison

Active Member
Joined
Aug 1, 2012
Messages
343
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm in a pickle and I can see a way out of it, but just not how to do it, arrghhhhhhhh!

We've got a [looong] list of more than 10,000 records which has on it:
Col A: old_product ID's
Col B: their customers.
(one old_product ID can have multiple customers)


And we need to work out how to integrate our new information which is even longer which has:
[this on a separate file...]
Col A: new_product ID
Col B: its associated products
(one new_product ID can have multiple associated products).


What we'd really like is a new listing which shows:


Col A: old_product ID
Col B: their_customers
Col C: new_product ID's
Col D: multiple_associated_products


The way I'd done this on a small scale was by duplicating rows and vlookups and attempted index matches, but frankly it's a mess and I wonder if somebody in the lovely world of "mr excel" may have some better ideas? :)


I'm open to using helper columns, UDF's, macro's and buying people a coffee to help get a method which will work!


Best


Neil


PS just to add a further fly in the ointment, rather than doing an exact match on the new and old product_ID's, they would like the list to take into account "partial matches" where the new_product_id *contains* the old_product_ID
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Can you supply a representative list of both old & new IDs, along with an indication of which numbers "match"
 
Upvote 0
Thanks Fluff, hope this helps:

File 1 = Old_product ID

Col A: old_product_IDRow B: Customers
appleJohn
appleJane

<tbody>
</tbody>

File 2 = new_product_IDs

Col A: new_product_IDCol B: associated products
applesoranges
applespears

<tbody>
</tbody>


File 3 = what we are hoping to acheive:

As regards the match: as "apple" is contained in "apples", that would therefore deemed to be a match
ie. if the old_product_id is contained in (or equals) the new_product_ID, it's a match
95% of the time, the product_id's are a mixture of upper or lower case letters and numbers
So ideally, any match formula would be "non-case-dependent"
Also the product_Id's are just sometimes only letters or only numbers (so it would be good to take that into account too!)
Old_product_IDCustomersNew_product_IDAssociated Products
applejohnapplesoranges
applejohnapplespears
applejaneapplesoranges
applejaneapplespears

<tbody>
</tbody>

I've explained to the powers-that-be that these lists will end up having more and more rows as a result of organising the information in this way...
But apparently that isn't as important as the right people getting a report organised in this way!!!
 
Last edited:
Upvote 0
We need a representative sample of your actual data, not some made up values. Bearing in mind you said
rather than doing an exact match on the new and old product_ID's, they would like the list to take into account "partial matches" where the new_product_id *contains* the old_product_ID
How do you expect anybody to manage that with the fake data you just supplied?
 
Upvote 0
Sorry, I thought it may have been easier to explain using those examples. If more examples would help, please let us know


File 1 = Old_product ID

Col A: old_product_IDRow B: Customers
MC68HC11A1FNCRT Ltd
MC68HC11A1FNEldocis SA

<tbody>
</tbody>


File 2 = new_product_IDs

Col A: new_product_IDCol B: associated products
MC68HC11a1F/SMDSN74LS240J
MC68HC11a1F/SMDSN74LS244J

<tbody>
</tbody>


File 3: what we're after

Old_product_IDCustomersNew_product_IDAssociated Products
MC68HC11A1FCRT LtdMC68HC11a1F/SMDSN74LS240J
MC68HC11A1FEldocis SAMC68HC11a1F/SMDSN74LS244J
MC68HC11A1FCRT LtdMC68HC11a1F/SMDSN74LS240J
MC68HC11A1FEldocis SAMC68HC11a1F/SMDSN74LS244J

<tbody>
</tbody>


Hope that helps!

 
Upvote 0
*apologies, old product ID should read: MC68HC11A1F not MC68HC11A1FN

File 1 = Old_product ID

Col A: old_product_IDRow B: Customers
MC68HC11A1FCRT Ltd
MC68HC11A1FEldocis SA

<tbody>
</tbody>

 
Upvote 0
Put this code in the "old" workbook & with both books open try
Code:
Sub mergedata()
   Dim Ary1 As Variant, Ary2 As Variant, Oary As Variant
   Dim r As Long, i As Long, j As Long
   
   Ary1 = ThisWorkbook.Sheets("[COLOR=#ff0000]old[/COLOR]").Range("A1").CurrentRegion.value2
   Ary2 = Workbooks("[COLOR=#ff0000]abc.xlsx[/COLOR]").Sheets("[COLOR=#ff0000]New[/COLOR]").Range("A1").CurrentRegion.value2
   ReDim Oary(1 To UBound(Ary1) * UBound(Ary2), 1 To 4)
   For r = 2 To UBound(Ary1)
      i = i + 1
      Oary(i, 1) = Ary1(r, 1)
      Oary(i, 2) = Ary1(r, 2)
      For j = 2 To UBound(Ary2)
         If InStr(1, Ary2(j, 1), Oary(i, 1), 1) > 0 Then
            If Oary(i, 3) = Empty Then
               Oary(i, 3) = Ary2(j, 1)
               Oary(i, 4) = Ary2(j, 2)
            Else
               i = i + 1
               Oary(i, 1) = Ary1(r, 1)
               Oary(i, 2) = Ary1(r, 2)
               Oary(i, 3) = Ary2(j, 1)
               Oary(i, 4) = Ary2(j, 2)
            End If
         End If
      Next j
   Next r
   ThisWorkbook.Sheets("[COLOR=#ff0000]Sheet1[/COLOR]").Range("A2").Resize(i, 4).Value = Oary
End Sub
Change values in red to suit.
This will put the result in the "old" workbook
 
Upvote 0
Wow, this is looking amazing! But I got an error message which reads "subscript out of range" - which is most probably my fault.....!

I've renamed files and sheets (which I was hoping would suit the code above but I think this is where I've messed up??!

Old Info:
Old.xlsm
Sheet is also called: old

New Info:

ABC.xlsx
sheet is called: new


I inserted the code only into Old.xlsm

As I said, I kept the red font above as it was....

"old" kept as "old"
"abc.xlsx" kept as "abc.xlsx"
"New" kept as "new"
"Sheet1" kept as Sheet1

When I hit AltF8 it brought up the Macro: "Sheet1.mergedata" which I ran on all Open Workbooks, but the error was "subscript out of range"




..... your help really is much appreciated!!!



PS If the above works out, then I'm thinking it may be something on the field headers that I've messed up...?
 
Upvote 0
If you click debug, what line of code is highlighted?
 
Upvote 0
When I hit Alt F8, the options are to press "ok" or "help" when the "subscript out of range" error message pops up. "ok" seems to shut the pop up window and "help" seems to open an internet browser.

And when I view the code via hit debug... the options are:
step into: takes me the first line of code: sub mergedata ()
step over: highlights: "
Ary1 = ThisWorkbook.Sheets("old").Range("A1").CurrentRegion.Value2"
...but if I click step over again, it highlights the next line Ary2... etc etc

The debugger doesn't seem to be highlighting a particular line of code, unless I'm mistaken?
 
Upvote 0

Forum statistics

Threads
1,215,242
Messages
6,123,830
Members
449,127
Latest member
Cyko

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