Separating Cell contents in VBA Strings

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I would like to separate values held in a cell. The cell content is produced from a web query and is of the format below:

"11.00+1.00 (+10.00%)"

I would like to use the leftmost '.' (period) as a reference point if necessary. I would like to set as a variable value any numbers to the left of the left most period, the period, and the two digits to the right of the left most period. Essentiallly I would like to take the stock value from the entire cell contents. Any ideas on how best to do this?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Excel Workbook
AB
111.00+1.00 (+10.00%)11.00
29.03+1.00 (+10.00%)9.03
Sheet1
 
Upvote 0
Thanks for the reply!

The VBA code that seems to be working is:

Code:
Range("A1").value = "=MID(A2,1,SEARCH(""."",A2)+2)"
 
Upvote 0
Thanks for the reply!

The VBA code that seems to be working is:

Code:
Range("A1").value = "=MID(A2,1,SEARCH(""."",A2)+2)"
You are welcome.

If you want a numeric extract, in VBA (your extract is a string not a number), maybe:
Code:
With Range("A1")
     .Formula= "=MID(A2,1,SEARCH(""."",A2)+2)+0"
     .Value = .Value
End With
Assuming your string is in A2 and you want the numeric extract in A1.
 
Upvote 0
YIf you want a numeric extract, in VBA (your extract is a string not a number), maybe:
Code:
With Range("A1")
     .Formula= "=MID(A2,1,SEARCH(""."",A2)+2)+0"
     .Value = .Value
End With
Assuming your string is in A2 and you want the numeric extract in A1
You could also use this...

Range("A1") = Val(Range("A2"))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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