APPEND WITH TEXT AFTER EACH COMMA IN A CELL WITH A DESIRED TEXT

meer_ali

New Member
Joined
Jan 1, 2018
Messages
18
Hello Friends,

I'm trying to Append text with Prefix product to each text string after comma(,) within a cell. I'm trying with a formula of substitute but unable to achieve.

i'm using formulas as -

="product"&SUBSTITUTE(D5,CHAR(10),) where D4 has values ="PRODUCT"&SUBSTITUTE(D4,CHAR(10),) and ouput is as below:

PRODUCT9010, 9030, 9040, 9050


I needed as - PRODUCT9010, PRODUCT9030, PRODUCT9040, PRODUCT9050

Also, I tried with helper column set in F2 and
=IFERROR(FIND(CHAR(10),$D2,E2+1),LEN($D2))

=IFERROR("product"&RIGHT(LEFT($D2,F2-1),F2-E2-1)&"product"& CHAR(10),"")

But i'm getting ouput as below:

PRODUCT9010, 9030, 904PRODUCT


Can somebody help me in this regard, Appreciate your efforts. Thanks

APPEND TEXT AFTER EACH COMMA IN A CELL WITH DESIRED TEXT.xlsx
BCDEFGHIJKLM
1X0helper column formula for F2
29010, 9030, 90409010, 9030, 904016PRODUCT9010, 9030, 904PRODUCT    
3
49010, 9030, 9040, 9050li9010, 9030, 904li product9010, 9030, 9040
5
6 
7IFERROR("product"&RIGHT(LEFT($D2,F2-1),&"product"&mid($D2,F2-E2-1),"")
8
9179010, 9030, 9040IFERROR("product"&RIGHT(LEFT($D2,F2-1),&"product"&mid($D2,F2-E2-1),"")
10product9010, 9030, 904
11
12
1316FIND(",",D2),F2-E2-1,"",)
14=MID(A1,3)
15
16
17"product"&SUBSTITUTE(D2,CHAR(10),CHAR(10),"product"&LEN(MID($D2,F2-1),F2-E2-1)&CHAR(10))
18
19YES9010, 9030, 904
20PRODUCT9010, 9030, 9040, 9050
21
22
23
24
work
Cell Formulas
RangeFormula
F2F2=IFERROR(FIND(CHAR(10),$D2,E2+1),LEN($D2))
H2H2=IFERROR("PRODUCT"&RIGHT(LEFT($D2,F2-1),F2-E2-1)&"PRODUCT"& CHAR(10),"")
I2:K2I2=IFERROR("li"&RIGHT(LEFT($D2,G2-1),G2-F2-1)&"/li"& CHAR(10),"")
H4H4=IFERROR("li"&RIGHT(LEFT($D2,F2-1),F2-E2-1)&"li"& CHAR(10),"")
I4I4="product"&D2
G6G6=IFERROR("<li>"&RIGHT(LEFT($D2,#REF!-1),#REF!-E2-1)&"</li>"& CHAR(10),"")
H9H9="17"&SUBSTITUTE(D2,CHAR(10),CHAR(10)&"17")
H10H10=IFERROR("product"&RIGHT(LEFT($D2,F2-1),F2-E2-1),"product"&MID($D2,LEFT($D2,F2-1),F2-E2-1))
B13B13=IFERROR(FIND(CHAR(10),$D2,E2+1),LEN($D2))
B19B19=IFERROR("YES"&RIGHT(LEFT($D2,F2-1),F2-E2-1)& CHAR(10),"")
B20B20="PRODUCT"&SUBSTITUTE(D4,CHAR(10),)


APPEND TEXT AFTER EACH COMMA IN A CELL WITH DESIRED TEXT.xlsx
B
1X0
work
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Trying to pick something out of that mess, is this what you want?
Excel Formula:
="PRODUCT "&SUBSTITUTE(D2,", ",CHAR(10)&"PRODUCT ")
 
Upvote 0
Solution
VBA approach assumes that the numbers are in column B and result will be place in column C. Change the range (in red) to suit your needs.
Rich (BB code):
Sub AppendText()
    Application.ScreenUpdating = False
    Dim LastRow As Long, rng As Range, spltRng As Variant, i As Variant
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each rng In Range("B2:B" & LastRow)
         spltRng = Split(rng, ", ")
         For i = LBound(spltRng) To UBound(spltRng)
            If rng.Offset(, 1) = "" Then
                rng.Offset(, 1) = "PRODUCT" & spltRng(i)
            Else
                rng.Offset(, 1) = rng.Offset(, 1) & ", " & "PRODUCT" & spltRng(i)
            End If
        Next i
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Trying to pick something out of that mess, is this what you want?
Excel Formula:
="PRODUCT "&SUBSTITUTE(D2,", ",CHAR(10)&"PRODUCT ")

Thanks alot for your effort. Your formula works,... absolutely good...

="PRODUCT"&SUBSTITUTE(D2,", ",CHAR(10)&","&"PRODUCT")

Thanks again for your quick response :)
 
Upvote 0
Thanks alot for your efforts too for VBA code which is working like butter smooth just one-click.

Thanks once again for your quick response..: :)



VBA approach assumes that the numbers are in column B and result will be place in column C. Change the range (in red) to suit your needs.
Rich (BB code):
Sub AppendText()
    Application.ScreenUpdating = False
    Dim LastRow As Long, rng As Range, spltRng As Variant, i As Variant
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each rng In Range("B2:B" & LastRow)
         spltRng = Split(rng, ", ")
         For i = LBound(spltRng) To UBound(spltRng)
            If rng.Offset(, 1) = "" Then




VBA approach assumes that the numbers are in column B and result will be place in column C. Change the range (in red) to suit your needs.
Rich (BB code):
Sub AppendText()
    Application.ScreenUpdating = False
    Dim LastRow As Long, rng As Range, spltRng As Variant, i As Variant
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each rng In Range("B2:B" & LastRow)
         spltRng = Split(rng, ", ")
         For i = LBound(spltRng) To UBound(spltRng)
            If rng.Offset(, 1) = "" Then
                rng.Offset(, 1) = "PRODUCT" & spltRng(i)
            Else
                rng.Offset(, 1) = rng.Offset(, 1) & ", " & "PRODUCT" & spltRng(i)
            End If
        Next i
    Next rng
    Application.ScreenUpdating = True
End Sub
rng.Offset(, 1) = "PRODUCT" & spltRng(i) Else rng.Offset(, 1) = rng.Offset(, 1) & ", " & "PRODUCT" & spltRng(i) End If Next i Next rng Application.ScreenUpdating = True End Sub

VBA approach assumes that the numbers are in column B and result will be place in column C. Change the range (in red) to suit your needs.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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