• 0

[VBA] VLOOKUP Comma Separated Values in Excel 2007?


Question

In an attempt to make my job easier, I am having to review data from one web site against data from another web site. This also means translating data from the data on Website A to match the appropriate data on Website B. For example (just pretend UPCs are that short).

Worksheet A
UPC  SiteAID  Name	Associated
001  954	  Fun	 137,321
002  137	  Happy   954,321
003  862	  Sad	 
004  432	  Mad	 554
005  684	  Bored   874
006  321	  Silly   954,137
008  554	  Angry   432
010  874	  Mellow  

Worksheet B
UPC  SiteBID  Name
001  ABD	  Fun
002  TYF	  Happy
006  MSD	  Silly
007  IUE	  Weird   
009  WQT	  OK	  

Worksheet C
UPC  AllID	Name	Associated
001  ABD	  Fun	 TYF,MSD
002  TYF	  Happy   ABD,MSD
006  MSD	  Silly   ABD,TYF
007  IUE	  Weird
009  WQT	  OK

As you can see, Worksheet A shows the associations with its own SiteID. Worksheet B doesn't show any associations, but would like to use the associations in Worksheet B with its own SiteIDs (as shown in Worksheet C, the final product).

A regular VLOOKUP won't work here, so after some searching, I did find some code that would do a MultiVLOOKUP, essentially putting the data from the cell into an array, performing a VLOOKUP on each value in that cell, and output its values separated by commas.

Option Explicit
Function MultiVLOOKUP(LookUpVal, LookUpRng As Range, LookUpCol As Long)
	Dim v, w, i, rng As Range

	v = Split(LookUpVal, ",")
	ReDim w(UBound(v, 1))

	For i = LBound(v, 1) To UBound(v, 1)
		w(i) = WorksheetFunction.VLookup(Val(v(i)), LookUpRng, LookUpCol, False)
	Next i

	MultiVLOOKUP = Join(w, ",")
End Function

From what I understand, I had to put these data as a new module in the Workbook (which I did), but every time I attempt to run the code, I get a #NAME? or #VALUE! error (depending on if I'm doing a VLOOKUP for the needed LookUpVal or using straight data for the LookUpVal).

From what I can tell, it's hitting some issues when it doesn't find matching data, but that's just my guess. Can anyone offer any insight into this issue?

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

  • Recent Achievements

    • One Month Later
      Devesh Beri earned a badge
      One Month Later
    • Week One Done
      Harold57 earned a badge
      Week One Done
    • Rookie
      Brett76 went up a rank
      Rookie
    • One Month Later
      Brett76 earned a badge
      One Month Later
    • Apprentice
      Snake Doc went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      588
    2. 2
      ATLien_0
      236
    3. 3
      Xenon
      149
    4. 4
      Michael Scrip
      139
    5. 5
      +FloatingFatMan
      119
  • Tell a friend

    Love Neowin? Tell a friend!