Tim Hanson
Member
Hello,
I am trying to split each cell from column A to the last column on ", " in sheet orgs
Then test each element against a master list in sheet A to see if any of the split elements have a match in the list
If so the replace the matched element of the split cell from Column B in sheet A
I can not get how to properly Re-Join my split cell with the replace values from the match and replacement
Ex:
sheet(Orgs)
Cells(2,1) = a,b,c,d
Sheet(A)
Then
Cells(2,1) = a,w,c,z
I appreciate any help on this I have been trying for hours, to no avail
I have uploaded a file
Thanks
Helper Function
I am trying to split each cell from column A to the last column on ", " in sheet orgs
Then test each element against a master list in sheet A to see if any of the split elements have a match in the list
If so the replace the matched element of the split cell from Column B in sheet A
I can not get how to properly Re-Join my split cell with the replace values from the match and replacement
Ex:
sheet(Orgs)
Cells(2,1) = a,b,c,d
Sheet(A)
Code:
ColA ColB
a a
b w
c c
d z
Then
Cells(2,1) = a,w,c,z
I appreciate any help on this I have been trying for hours, to no avail
I have uploaded a file
Thanks
Code:
Sub FindReplace_Orgs()
Dim FindValues As Variant, ReplaceValues As Variant, G As Variant, temp As Variant
Dim wsFV As Worksheet, wsRV As Worksheet
Dim sLR As Long, tLR As Long, i As Long, j As Long, n As Long
'Sheets("Orgs").Select
Set wsFV = ThisWorkbook.Worksheets("Orgs")
Set wsRV = ThisWorkbook.Worksheets("A")
sLR = wsFV.Range("A" & wsFV.Rows.Count).End(xlUp).Row
tLR = wsRV.Range("A" & wsRV.Rows.Count).End(xlUp).Row
For i = 2 To sLR
For j = 2 To tLR
G = Split(wsFV.Cells(i, 1).value, ", ")
temp = G
For n = LBound(G) To UBound(G)
If splitCell(wsFV.Range("A" & i), ", ", n) = wsRV.Cells(j, "A") Then
temp(i) = Join(wsRV.Cells(j, "B").value, ", ")
'MsgBox G(n) & " " & temp(i)
End If
Next n
Next j
Next i
wsFV.Range("A2:A" & sLR).value = temp
End Sub
Helper Function
Code:
Function splitCell(strValue As String, delim As String, Optional n As Long) As String
If strValue <> "" Then
splitCell = Split(strValue, delim)(n)
Else
strValue = ""
End If
End Function
Attachments
Last edited: