+ Reply to Thread
Results 1 to 10 of 10

Textbox formatting questions/problems

  1. #1
    Registered User
    Join Date
    09-11-2013
    Location
    NC, USA
    MS-Off Ver
    Excel 2013
    Posts
    16

    Question Textbox formatting questions/problems

    Hey Guys (and Gals)!

    New to the forum but have lurked for a while. Hopefully I can contribute as much as you guys have...guidance from this forum certainly has helped keep my sanity!!! :-p

    So, let me start with a question. I've searched but have not found exactly what I'm looking for, maybe its because I'm a VB newbie & may not recognize an answer even it was staring me in the face, lol. Anyway...

    I have a UserForm which moves the TextBox values to a data table when a command button is hit. The problem is that the values in the data table then show as text. I need them in numerical form so the pivot tables derived from the data table work properly. The two TextBox formats needed are 1) a normal number (temperature) and 2) a scientific number (ex: 1E-9). So, long story short, I'd like for the user to be able to enter his/her numbers in the TextBoxes & they end up as numbers (without errors) in the data table. Can someone assist me with this?

    Thanks in Advance,
    Jay

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Textbox formatting questions/problems

    Hi,

    You can always use the Function "Format" you can read more about it here http://www.techonthenet.com/excel/fo...mat_string.php

    So your code would look something like this:

    Please Login or Register  to view this content.
    See if it helps

    Thanks

  3. #3
    Registered User
    Join Date
    09-11-2013
    Location
    NC, USA
    MS-Off Ver
    Excel 2013
    Posts
    16

    Re: Textbox formatting questions/problems

    Quote Originally Posted by fredlo2010 View Post
    Hi,

    You can always use the Function "Format" you can read more about it here http://www.techonthenet.com/excel/fo...mat_string.php

    So your code would look something like this:

    Please Login or Register  to view this content.
    See if it helps

    Thanks

    Thanks! I will definitely check that out when I have time...

    So this would be inserted somewhere in my command button script (see below)?
    Private Sub CommandButtonSaveAndClose_Click()
    Dim nextrow As Integer
    'Moves data from userform to the data table
    nextrow = WorksheetFunction.CountA(Sheets("BakeDataTable").Range("E:E")) + 6
    Sheets("BakeDataTable").Cells(nextrow, 5) = TextBoxDate
    Sheets("BakeDataTable").Cells(nextrow, 6) = TextBoxBakeTemp
    Sheets("BakeDataTable").Cells(nextrow, 7) = TextBoxInternalTemp
    Sheets("BakeDataTable").Cells(nextrow, 8) = TextBoxDepoPressure
    Sheets("BakeDataTable").Cells(nextrow, 9) = TextBox2Hydrogen
    Sheets("BakeDataTable").Cells(nextrow, 10) = TextBox18Water
    Sheets("BakeDataTable").Cells(nextrow, 11) = TextBox28Nitrogen
    Sheets("BakeDataTable").Cells(nextrow, 12) = TextBox32Oxygen
    Sheets("BakeDataTable").Cells(nextrow, 13) = TextBox62P2
    Sheets("BakeDataTable").Cells(nextrow, 14) = TextBox75As
    Sheets("BakeDataTable").Cells(nextrow, 15) = TextBox91AsO
    Sheets("BakeDataTable").Cells(nextrow, 16) = TextBox124P4

    Unload UserFormNewEntry
    End Sub

  4. #4
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Textbox formatting questions/problems

    Hello,

    The final code should look like this. If I am missing anything you can add it in a similar fashion. Also I modified a little the way you find the last row of data.

    Please Login or Register  to view this content.
    Thanks

  5. #5
    Registered User
    Join Date
    09-11-2013
    Location
    NC, USA
    MS-Off Ver
    Excel 2013
    Posts
    16

    Re: Textbox formatting questions/problems

    Quote Originally Posted by fredlo2010 View Post
    Hello,

    The final code should look like this. If I am missing anything you can add it in a similar fashion. Also I modified a little the way you find the last row of data.

    Please Login or Register  to view this content.
    Thanks
    Great! I appreciate the help. Looks like that has the regular numbers (temps) taken care of. The Scientific numbers are still showing as text (errors) when added to the data table. Any ideas what can be done there? The users usually enter these as scientific (i.e. 1.00E-9). Again, thanks for the help...

  6. #6
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Textbox formatting questions/problems

    I don't know what field are supposed to be in scientific so i didnt program it.

  7. #7
    Registered User
    Join Date
    09-11-2013
    Location
    NC, USA
    MS-Off Ver
    Excel 2013
    Posts
    16

    Re: Textbox formatting questions/problems

    Ah, I see now! My son had me preoccupied earlier so I didn't catch that part of the changes you made. Just gave it a try and it works great!!!

    Thanks,
    Jay

  8. #8
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Textbox formatting questions/problems

    I am glad I helped. I should have made it pop out a little.

  9. #9
    Registered User
    Join Date
    09-11-2013
    Location
    NC, USA
    MS-Off Ver
    Excel 2013
    Posts
    16

    Re: Textbox formatting questions/problems

    After a little testing, I went back to the following to move the data to the table:
    nextrow = WorksheetFunction.CountA(Sheets("BakeDataTable").Range("E:E")) + 6

    Using the following, it always started 1 row below the table.
    nextrow = Sheets("BakeDataTable").Cells(Rows.Count, "E").End(xlUp).Row + 1

    It works so I'm fine with it. If there is a more efficient or proper way, please let me know...

  10. #10
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Textbox formatting questions/problems

    I dont think one is better or anything, but the one i gave you is more of a coding vba way while the other is subject to worksheet contents, blanks, zeros...etc. Its the way you will find most of the times in forms like this it might not work 100% with you because i am guessing you have 5 rows before your actual data. With the form i gave you always goes from the buttom up and not downwards.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Problems with Exit event for Textbox
    By tfurnivall in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-11-2013, 11:03 AM
  2. Excel VBA TextBox navigation problems
    By FWB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2010, 01:00 PM
  3. [SOLVED] Having problems with textbox setfocus
    By Terry K in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2006, 09:30 AM
  4. [SOLVED] Coding questions about UserForm TextBox
    By excelnut1954 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-13-2006, 11:10 AM
  5. Textbox questions
    By Stuart in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-04-2005, 06:06 AM

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