Consulting

Results 1 to 8 of 8

Thread: need vbd string to number

  1. #1

    need vbd string to number

    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
    Attached Images Attached Images

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    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?

    David


  3. #3
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [VBA]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))[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  4. #4
    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

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    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.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    Quote Originally Posted by CatDaddy
    [vba]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))[/vba]
    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...

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

  7. #7
    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

  8. #8
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    interesting! i didnt even consider evaluate
    ------------------------------------------------
    Happy Coding my friends

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •