How to abstract a number from a string?

D

Danny Hoon

Hi all,

I'm trying abstract second number from a cell.
If cell a1=1234, how do I abstract 2 using a function?
I will need to use 2 for some math calculation.

I tried this but it don't work.

Function test(num As String)
test = num.char(1)
End Function

Thank for assisting.
 
D

Dave Peterson

Function test(num As String) as long
test = mid(num,2,1)
End Function

(with no validity checks at all!)
 
D

Danny Hoon

Thanks Dave!!!
Care to explain this line?
Function test(num As String) as long <== you are casting the String to a
Long data type?
 
D

Dave Peterson

Yep.

You said that it would be used for further math calculations.

Danny said:
Thanks Dave!!!
Care to explain this line?
Function test(num As String) as long <== you are casting the String to a
Long data type?
 
Top