+ Reply to Thread
Results 1 to 15 of 15

Code to format number input in textbox controls (based on tag) in userform

  1. #1
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Code to format number input in textbox controls (based on tag) in userform

    Greetings,

    I have started creating a userform with several textbox controls. The input in these textbox controls should be displayed either in the "Percent" or "Standard" format. Instead of having a code for each textbox control, I used the tag property "P" & "S" and put together this code:

    Please Login or Register  to view this content.
    But when I enter a number in the textbox control, the display does not change.

    Can someone please tell me what is wrong?

    Many thanks
    Asha
    Last edited by asha3010; 07-05-2010 at 04:18 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code to format number input in textbox controls (based on tag) in userform

    That code will only run when the Form initialises

    You would need to create a Procedure in the UserForm module & call it using each TextBox exit_event, the loop would not be needed then
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code to format number input in textbox controls (based on tag) in userform

    Here's a quick example

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Code to format number input in textbox controls (based on tag) in userform

    Hi royUK,

    Many thanks for your prompt response.

    Am I required to do this for each textbox that requires a "Percent" display:

    Please Login or Register  to view this content.
    Can you please confirm my understanding?

    Many thanks
    Asha

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code to format number input in textbox controls (based on tag) in userform

    Check the code that i have just posted

  6. #6
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Code to format number input in textbox controls (based on tag) in userform

    Hi royUK,

    Sorry - sent the message before I saw yours.

    Here' what I did - pasted the code after clicking on "view code" for the userform.

    I have attached the sample file. When I select dividend and type 24 next to the dividend % label, the display still shows 24.

    Can you please take a look?

    Much appreciated.
    Asha
    Attached Files Attached Files
    Last edited by asha3010; 07-02-2010 at 07:11 AM.

  7. #7
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Code to format number input in textbox controls (based on tag) in userform

    Can someone please please help me, I am unable to get the result with the code.

    Many thanks
    Asha

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Code to format number input in textbox controls (based on tag) in userform

    or
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Code to format number input in textbox controls (based on tag) in userform

    Thanks snb for your response.

    As I understand the code you provided has to be applied for each textbox that requires a "Percent" display.

    I was wondering if there was a single subroutine that can format all textboxes in the userform.

    Regards
    Asha

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code to format number input in textbox controls (based on tag) in userform

    You've pasted the code into the wrong place so that Option Explicit & Dim i as integer are randomly placed in the code,they should be at the top of the code module,please either ask or read the help Files if you don't recognise something like Option Explicit

    Why have you placed labels over Controls?

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code to format number input in textbox controls (based on tag) in userform

    You have just copied the code that I gave you into the module,so Option Explicit & Dim i as integer are in the wrong place,they should be at the top of the code module. If you see something like Option Explicit which you don't understand,then ask or read the help files,after all that's what they are there for.

    Why have you placed labels over the controls?

    You have paced the Exit code in a TextBox_Exit that doesn't even have a Tag property with a Value of ""

    Please Login or Register  to view this content.
    Last edited by royUK; 07-03-2010 at 03:26 PM.

  12. #12
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Code to format number input in textbox controls (based on tag) in userform

    Hi royUK,

    Thank you very much for the response.

    I did not know I was doing the wrong thing by placing the code where I did - as I have just demonstrated my knowledge of VBA is pathetic. Sorry for exasperating you.

    Why have you placed labels over the controls?
    I have not placed any labels over the controls. I have grouped some of the controls - is that what you are referring to?

    Many thanks again for your patience and support.
    Asha

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code to format number input in textbox controls (based on tag) in userform

    No problem, let me know if it works now

  14. #14
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Code to format number input in textbox controls (based on tag) in userform

    Yes the code works.

    Much appreciated
    Asha

  15. #15
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code to format number input in textbox controls (based on tag) in userform

    Thanks for letting me know

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1