Split array and re join

mdo8105

Board Regular
Joined
Nov 13, 2015
Messages
83
I have an array that I am able to split and get the individual text in it, then I take each string and find match on another sheet and grab the Id in the next column. I want to take the ID that I find and re join into an array.
Code:
v1 = Split(ws1.Cells(r, 7), ",")For i = 0 To UBound(v1)
           v2 = Application.WorksheetFunction.Index(ws2.Range("D:D"), Application.WorksheetFunction.Match(v1(i), ws2.Range("C:C"), 0))
           
          
        
        Next i
I want to take all that is returned in v2 and make an array delimited by commas and return back into a cell. I've Join, but I get a type mismatch with v2 variable.
 

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
8,808
You can just concatenate the results as you go, like:
Rich (BB code):
Dim str1 as String
v1 = Split(ws1.Cells(r, 7), ",")
For i = 0 To UBound(v1)
    v2 = Application.WorksheetFunction.Index(ws2.Range("D:D"), Application.WorksheetFunction.Match(v1(i), ws2.Range("C:C"), 0))
    str1 = str1 & "," & v2
Next i
Cells(r, 8) = Mid(str1, 2)
If you want to use Join, something like:
Rich (BB code):
Dim Str1() as string

v1 = Split(ws1.Cells(r, 7), ",")
Redim Str1(0 to UBound(v1)) 
For i = 0 To UBound(v1)
     Str1(i) = Application.WorksheetFunction.Index(ws2.Range("D:D"), Application.WorksheetFunction.Match(v1(i), ws2.Range("C:C"), 0))
Next i
Cells(r, 8) = Join(Str1,",")
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,523
Office Version
365
Platform
Windows
How about something like
Code:
   Dim v1 As Variant, v2 As Variant
   Dim v3 As String
   Dim i As Long
   
   v1 = Split(Ws1.Cells(r, 7), ",")
   For i = 0 To UBound(v1)
      v2 = Application.Index(Ws2.Range("D:D"), Application.Match(v1(i), Ws2.Range("C:C"), 0))
      If Not IsError(v2) Then
         If v3 = "" Then v3 = v2 Else v3 = v3 & "," & v2
      End If
   Next i
   Ws1.Cells(r, 8).Value = v3
   v3 = ""
 

mdo8105

Board Regular
Joined
Nov 13, 2015
Messages
83
So sorry for the late response. Eric W, that code worked like a charm. Thank you so much.
 

Forum statistics

Threads
1,078,437
Messages
5,340,277
Members
399,361
Latest member
Linford

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top