Reading certain characters from a cell

Derek_35

New Member
Joined
Apr 21, 2002
Messages
25
I'm opening a file I have no control over and cell D24 reads as follows :

Cash Left: ###,###

I want to only read in the # into an integer, not a string. How can I do this?

Thanks...
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Cell D24 = "Cash Left: 392,000"

dim money as integer

I want an integer variable (money) equal to 392,000.

I can read the the cells value as a string, but a) I do not want the "Cash Left:" part and b) I want 392,000 as an integer, not a string.
 
Upvote 0
Try this, changing the value of sMoney to whatever cell you want.

<pre>
Public Sub main()
'Cell D24 = "Cash Left: 392,000"
Dim sMoney As String
Dim iMoney As Long

sMoney = "Cash Left: 392,000"
iMoney = LTrim(RightString(sMoney, ":"))

MsgBox iMoney
End Sub
Private Function RightString(ByVal sText As String, ByVal sSeparator As String) As String
RightString = Right(sText, Len(sText) - InStr(1, sText, sSeparator))
End Function</pre>

I'm assuming that you are always going to have colon in the sentence before the number.

HTH
 
Upvote 0
Hi,

Are you reading the cell into a variable, or do you want to change the cell on the worksheet?

If the latter, try:

Sub test()
Dim cell As Range

For Each cell In Selection
cell = WorksheetFunction.Substitute(cell, "Cash Left:", "") + 0
Next cell
End Sub

Note also that you cannot read your example into an Integer variable. Change it to Long or Double.

myVari = WorksheetFunction.Substitute(cell, "Cash Left:", "") + 0

If you have Excel 2000 or XP, I believe there is a Replace function that can be used instead of worksheetfunction.substitute

HTH,
Jay

EDIT: Scratch this answer. Mark's is nicer.
This message was edited by Jay Petrulis on 2002-04-22 13:26
 
Upvote 0
Oh for God's sakes Jay! You're just far too nice to me. :biggrin:

I liked your solution. I wouldn't even have considered that, because I didn't know it existed.
 
Upvote 0

Forum statistics

Threads
1,214,575
Messages
6,120,334
Members
448,956
Latest member
Adamsxl

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