Extract data after "-" VBA

Liam4567

New Member
Joined
Jan 6, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
**VBA**

Hi

I have a string that will change daily and looks something like this "09876 k-wef234 £45678.99 Option 4 -£123456.57"

I am trying to find the best way of extracting the "-£123456.57" after "Option 4 -£123456.57". I need the code to always look for Option 4 as that is the one part that will always stay the same, and the number after will always start with a minus. It needs to look for Option 4 as it is going to loop through multiple rows of data looking for the words Option 4.

I will then be using that figure (-£123456,57) to be the value of a cell on another sheet.

Thanks in advance.
 

Liam4567

New Member
Joined
Jan 6, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
So there will only be one cell in column A containing "Option 4"?
Yes correct :)

There will be lots or rows containing data, and some may say Option 5, but only one will contain 'Option 4' and then I just need the figure after that into cell D2 on sheet2, and that figure will always start with a -
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
49,244
Office Version
  1. 365
Platform
  1. Windows
I edited my previous post. Does the edit answer your question?
 

Liam4567

New Member
Joined
Jan 6, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
So there will only be one cell in column A containing "Option 4"?

Edit:
If so, do you really need vba for this or would a formula like this do?

Excel Formula:
=-RIGHT(SUBSTITUTE(VLOOKUP("*Option 4*",PDF!A1:A1000,1,0),"£",REPT(" ",20)),20)
That worked, thanks for your help :)
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
49,244
Office Version
  1. 365
Platform
  1. Windows
You're welcome. Glad we got there in the end. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,133,832
Messages
5,661,210
Members
418,620
Latest member
JUrq

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
Top