Copy text after 3rd comma from the right in a cell

derricksmith

New Member
Joined
Aug 29, 2017
Messages
2
Hi,


I have an address the following formats in a cell:
Customer Name, 1 Address, 2 Address, City, ST, 00000-0000, US
Other Customer, 1 Address, City, ST, 12345, US


I need a formula to just extract the “ST” state information. My problem is sometimes there is no “2 Address” and corresponding comma. So using “Text to Columns” doesn’t create consistent data.


As you can see the number of commas can vary. How I extract from the “ST” from after the 3rd comma from the right?


Thanks!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
derricksmith,

Welcome to the Board.

If you're comfortable with a vba approach, you might consider the following...

Code:
Sub ExtractState_1020865()
Dim arr As Variant
Dim r As Range
For Each r In Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
    arr = Split(r, ",")
    r.Offset(0, 1).Value = Trim(arr(UBound(arr) - 2))
Next r
End Sub

The code assumes your list of addresses is in Column A, and will extract the state info to Column B.

Cheers,

tonyyy
 
Upvote 0
Hi,


I have an address the following formats in a cell:
Customer Name, 1 Address, 2 Address, City, ST, 00000-0000, US
Other Customer, 1 Address, City, ST, 12345, US


I need a formula to just extract the “ST” state information.
Give this formula a try...

=TRIM(LEFT(RIGHT(SUBSTITUTE(A1,",",REPT(" ",200)),600),200))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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