VBA converting number string into number

  • In cell B7, I have the number 32-338, but because of the "-" , excel thinks it's text. Is there a way to get 32-338 as a number?


    The end point is that I need it to look at cell B7, get the number (in this case 32-338) and then also give me the previous and next numbers (32-337 and 32-339)


    I tried

    Code
    Range("b7").NumberFormat = "#"

    , but that turns it into 32.


    I also can't assume that the numbers on the right will always be two digits, or that the numbers on the left will be three.

  • Re: VBA converting number string into number


    try:

    Code
    Range("B7") = Replace(Range("B7").Value, "-", "")


    [COLOR="#0000CD"]MODERATOR EDIT
    Please remember to use code tags, including with single-line code snippets.
    Thanks.[/COLOR]

  • Re: VBA converting number string into number


    Hi All,


    I have created a textbox and linked it excel column H and i am trying to convert the text format to numeric format, when userform is submitted.


    Please help on how to change the format from text to number and also advise where to write the code in VBA.


    Regards
    Shiva

  • Re: VBA converting number string into number


    Shiva,


    Welcome to Ozgrid.


    Always start a new thread for your question. Posting your question in threads started by others is known as thread hijacking and is against the policy of this forum.
    If you think it helps clarify your situation you may include a link to this thread.


    Be sure to give your thread a search-friendly title that accurately describes your thread content or objective.


    Thanks

  • Re: VBA converting number string into number


    What number does "32-337" represent?


    -305 ? (subtraction)


    32.337 ? (the dash acts as a decimal indicator)


    or does it represent the set of all integers between 32 and 337?


    What number does "32-337" represent?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!