Convert String to Decimal in Userform Textbox

  • Hi All,


    I have truly searched basically everwhere I could. My userform has about 133 Combo and Textboxes, some of them take data to the worksheet, and the other retrieve data from the worksheet. I have one Textbox (PBUT101) that returns data from the worksheet, but I have tried everything to get it to display the value as eg 23.45 %, I keep on getting a string value.


    As soon as I change the code to Dec or Dbl from Str I get a Run-time error '13' - Type mismatch. I really do not know what to change anymore.


    just that one TextBox that needs to display correctly


  • Re: Convert String to Decimal in Userform Textbox


    Hi,


    What is the value in the worksheet, before you attempt to do anything to it with your macro? And is it stored in the worksheet as a numeric value, or text?


    Whatever you do to the 'number', irrespective of how it is displayed, in a textbox it is always going to be stored as text.


    Without seeing your data, you could try something like:

    Code
    Me.PBUT101.Value = Format(Ques.Range("L151").Value * 100, "0.00") & "%"


    This assumes that your original data is stored in Excel in number format.

    [COLOR="Purple"]Regards,[/COLOR]
    [COLOR="Purple"]Batman.[/COLOR]

  • Re: Convert String to Decimal in Userform Textbox


    Hi Batman,


    The cell is Percentage, but I have changed it to numeric, and changed the code as indicated. Works 100%. Thanks so much

  • Re: Convert String to Decimal in Userform Textbox


    The change of cell display format should not make any difference. The underlying value will still be the same, in a number format. The only difference will be in the way that the number is displayed to the screen.

    [COLOR="Purple"]Regards,[/COLOR]
    [COLOR="Purple"]Batman.[/COLOR]

Participate now!

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