PDA

View Full Version : need vbd string to number



vpn25
06-21-2012, 08:15 AM
i have 1 image here, with text as string " truc 11 : 2*4*3=24 and i want value calculator is 2 *4*3, and this string always stop by " :" . Ex
trục 11 : 2*4*3 this color blue is value calculator and result show in range when i finish.please help me.thanks all.i am vietnamese

Tinbendr
06-21-2012, 09:57 AM
Is the string in B1 or B2.

Will the text truc always be in the cell?

Will the result always be at the end?

Could we just return the value to the right of the equal sign? In this case, the 24?

Is the calculation always correct?

CatDaddy
06-21-2012, 10:11 AM
Dim str() as Variant
Dim i As integer

str = Split(Range("B2").Text, " ")
str = Split(str(4), "*")
i = CInt(str(0)) * CInt(str(1)) * CInt(str(2))

vpn25
06-21-2012, 09:57 PM
thanks post.but you can show me ex with file excel?? please do it with my form, result show in Cell B2 and D1 value is 24.thanks for all

Aussiebear
06-22-2012, 02:06 AM
Attach a sample workbook rather than a thumbnail. Click on Go Advanced, then scroll down to Manage Attachments and follow the prompts from there. While we offer assistance, we don't necessarily want to have to reconstruct workbooks for people as well.

CodeNinja
06-22-2012, 10:43 AM
Dim str() as Variant
Dim i As integer

str = Split(Range("B2").Text, " ")
str = Split(str(4), "*")
i = CInt(str(0)) * CInt(str(1)) * CInt(str(2))

CatDaddy,
That would work fine if you are only going to have 3 arguments with 2 operators both being *... might be more effective if you did something like this...

dim str as string
dim dAnswer as double
str = trim(split(sheet1.cells(2,2), ":") (1))
dAnswer = evaluate(str)

Trebor76
06-27-2012, 04:27 PM
Or in a single line command:


Option Explicit
Sub Macro1()

'Return the value of the formula =MID(B2,FIND("=",B2)+1,LEN(B2)-FIND("=",B2)+1) to cell A4
Range("A4").Value = Evaluate("MID(" & Range("B2").Address & ",FIND(""=""," & Range("B2").Address & ")+1,LEN(" & Range("B2").Address & ")-FIND(""=""," & Range("B2").Address & ")+1)")

End Sub

CatDaddy
06-28-2012, 10:02 AM
interesting! i didnt even consider evaluate :)