Trim everything before a character

urobee

Board Regular
Joined
Jan 30, 2015
Messages
98
Hy,

I have a text looks like:

"abcdef | 123456 | xyz"

I need to show only the last few character after the last " | " character, (delete everything before the last " | " and the pipe character too)
so in this case i need: "xyz" (the number of the characters is different all the time)

Oh, and i need to do this with VBA, not with formula.

Thanks for your help! :)
 
Last edited:
Sorry, but i have another problem:
The example is the same: "abcdef | 123456 | xyz"
I need to modify the file so i need the text from the middle : "
123456"

 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Sorry, but i have another problem:
The example is the same: "abcdef | 123456 | xyz"
I need to modify the file so i need the text from the middle : "
123456"
If there are always only three delimited fields, then you would want to use the suggestion Haluk made in Message #9 as s basis...

If you will need all of these in the same procedure, then declare a Variant variable which I'll name Arr for this example, and do something like this...'
Code:
Dim FirstField As String
Dim MiddleField As String
Dim LastField As String
Dim Arr As Variant
Arr = Split(ComboL.Value, "|")
FirstField = Trim(Arr(0))
MiddleField = Trim(Arr(1))
LastField = Trim(Arr(2))
If you will only need any one of these without the other two, then you can use the Split function directly...
Code:
MiddleField = Split(ComboL.Value, "|")([B][COLOR="#FF0000"]1[/COLOR][/B])
You would use 0 in place of the 1 for the first field and 2 in place of the 1 for the last field.
 
Last edited:
Upvote 0
If there are always only three delimited fields, then you would want to use the suggestion Haluk made in Message #9 as s basis...

If you will need all of these in the same procedure, then declare a Variant variable which I'll name Arr for this example, and do something like this...'
Code:
Dim FirstField As String
Dim MiddleField As String
Dim LastField As String
Dim Arr As Variant
Arr = Split(ComboL.Value, "|")
FirstField = Trim(Arr(0))
MiddleField = Trim(Arr(1))
LastField = Trim(Arr(2))
If you will only need any one of these without the other two, then you can use the Split function directly...
Code:
MiddleField = Split(ComboL.Value, "|")([B][COLOR=#FF0000]1[/COLOR][/B])
You would use 0 in place of the 1 for the first field and 2 in place of the 1 for the last field.

Thanks!

I really like this site, i always learn here a lot! :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,217,410
Messages
6,136,462
Members
450,013
Latest member
k4kamal

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