Separate out a value in a string

AndyDevine1

Board Regular
Joined
Jun 1, 2006
Messages
172
hi there
if I have a table where the character strings look like

SSSS-Hello there-asasas_As.jpeg
DDDD_SSSS-GOOGBE-asasas_As_Somemoretext.jpeg

Is there any way to copy the information between the dashes '-' into a new column in my table?

In this example to get 'Hello there' and 'GOOGBE' into the new column?

Many thanks

Andy
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi.

Will those two dashes always be the only two dashes within a given string?

Regards
 
Upvote 0
You should be able to do this in a query using a Calculated Field.

Assuming that you always will have exactly 2 dashes in each string, this should work:
MyString: Mid([FieldName],InStr([FieldName],"-")+1,InStrRev([FieldName],"-")-InStr([FieldName],"-")-1)
 
Upvote 0
Hi guys
just wanted to say thanks again for help...the yes in a previous response was to XOR but seems that was delayed in being posted, so reads a bit confusing above......all good now...have nice evenings all
 
Upvote 0
Hi Joe4 and others
Can you please help modifying code below to cope with errors...so if it's an error it returns a different heading eg...Field 1 from table 1

MyString: Mid([FieldName],InStr([FieldName],"-")+1,InStrRev([FieldName],"-")-InStr([FieldName],"-")-1)

Many thanks

Andy
 
Upvote 0
What table/field are you applying the formula to?
What do the values in Table 1 Field1 look like?
Do you want to apply the same sort of logic to it, and just return the value of Field1, unaltered?
 
Upvote 0
Hi Joe
Thanks for your prompt reply

I've used the formula successfully in a make table query...so it reads from a table and creates a new table with the result in a new column

The query fails where the cell is blank or whether there are no "-"...

There shouldn't be any instances where this is the case, but 'just in case', I want to allow for this...and return the original value unaltered

Thanks again
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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