Results 1 to 6 of 6
  1. #1
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    250
    Thanks
    3
    Thanked 1 Time in 1 Post

    Convert Text to Numeric (VBA/Excel/2003)

    I have this massive project. When my client enters numbers into the TextBoxes on the UserForm, she wants it to return
    Alan

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Re: Convert Text to Numeric (VBA/Excel/2003)

    Youc could use
    <code>
    Val(Replace(Replace(txtCliBR, "$", ""), ",", ""))</code>

  4. #3
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    250
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Convert Text to Numeric (VBA/Excel/2003)

    Where should I do this, when I am writing to the saved file?
    Alan

  5. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Re: Convert Text to Numeric (VBA/Excel/2003)

    Your question was "Can I convert it back to numeric before/while saving it to the spreadsheet? Anybody got some sample code?"
    Say that the contents of txtCliBR are to be stored in cell B2 of Sheet1. You'd use

    Worksheets("Sheet1").Range("B2") = Val(Replace(Replace(txtCliBR, "$", ""), ",", ""))

    You could precede this with a check whether txtCliBR has actually been filled in.

  6. #5
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    250
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Convert Text to Numeric (VBA/Excel/2003)

    <big> <font face="Comic Sans MS">Has anyone told you that you are genius lately? I did not have my "smart hat" when I asked the 2nd question.</font face=comic> Already figured it out. </big> <img src=/S/bash.gif border=0 alt=bash width=35 height=39>

    I only save what absolutely must be used in the later calculation so it would have given the user an error earlier if something was not filled in.

    This "2 week" project has turned into 10 weeks.
    Alan

  7. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Text to Numeric (VBA/Excel/2003)

    Why not (if possible) simply format the appropriate worksheet cells to the $###,##0.00 format, and deal only with the numeric value in your code. e.g. with B2 formatted as above:
    <div style="width: 100%; background-color: #FFFFFF;"><code><font color=black>
    <font color=blue>Sub</font color=blue> test()
    <font color=blue>Dim</font color=blue> num <font color=blue>As</font color=blue> <font color=blue>Double</font color=blue>
    num = InputBox("Type your number")
    Worksheets("Sheet1").Range("B2") = num
    num = Worksheets("Sheet1").Range("B2")
    num = num * 2
    MsgBox num
    <font color=blue>End</font color=blue> <font color=blue>Sub</font color=blue>
    </font color=black></code></div hiblock>
    Alan

Posting Permissions

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