macro to pull some text from cells in a column

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone, have a problem with this hope you can help,

I'm looking for a macro that can Look down range C3:C and last row and if the cell contains the words "Add Ons:" take all the text after it and paste it in column L but if the extracted text has ";" in it only extract up to there (not including)

so if the words are:
Add Ons: Fuji Apple Salad
i want Fuji Apple Salad
but if its
"Add Ons: Coconut Street Corn;
Choose Sauce: Sweet Chili"
i just want Coconut Street Corn

please help if you can
Thanks
Tony


Add Ons: Coconut Street Corn;
Choose Sauce: Sweet Chili




Add Ons: Fuji Apple Salad
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
One option as a formula and not VBA:
Book1
AB
2 Add Ons: Coconut Street Corn; Choose Sauce: Sweet ChiliCoconut Street Corn
3 Add Ons: Fuji Apple SaladFuji Apple Salad
4Fuji Apple Salad
Sheet1
Cell Formulas
RangeFormula
B2:B4B2=BYROW(A2:A4,LAMBDA(x,LET( ts,TEXTSPLIT(CLEAN(x),{":",";"}), IF(INDEX(ts,,1)="Add Ons",TRIM(INDEX(ts,,2)),""))))
Dynamic array formulas.
 
Upvote 0
Try:
VBA Code:
Sub ExtractSuString()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long
    v = Range("C3", Range("C" & Rows.Count).End(xlUp)).Value
    For i = LBound(v) To UBound(v)
        If InStr(v(i, 1), "Add Ons:") = 1 And InStr(v(i, 1), ";") = 0 Then
            Range("L" & i + 2) = Trim(Split(v(i, 1), ":")(1))
        ElseIf InStr(v(i, 1), "Add Ons:") = 1 And InStr(v(i, 1), ";") = 1 Then
            Range("L" & i + 2) = Trim(Split(Split(v(i, 1), ":")(1), ";")(0))
        End If
    Next i
    Application.ScreenUpdating = False
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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