Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-14-2012, 08:42 AM
officeclerk officeclerk is offline Number format in Textbox on userform Windows 7 64bit Number format in Textbox on userform Office 2007
Novice
Number format in Textbox on userform
 
Join Date: Apr 2012
Posts: 2
officeclerk is on a distinguished road
Default Number format in Textbox on userform

I have a basic userform with textboxes for data entry. Is it possible to format the data so when it goes to the spreadsheet, that it will stay in number format instead of changing the cell format to text?



This is what they currently look like.
Code:
 
Private Sub TextBox1_Change()
Sheets("Sheet1").Range("B25").Value = Me.TextBox1
End Sub
Can this be done by changing the textbox properties?

Thank you.
Reply With Quote
  #2  
Old 04-16-2012, 10:48 PM
jolivanes jolivanes is offline Number format in Textbox on userform Windows XP Number format in Textbox on userform Office 2007
Advanced Beginner
 
Join Date: Sep 2011
Posts: 93
jolivanes will become famous soon enough
Default

You could try any of these.

Code:
Private Sub UserForm_Initialize()
TextBox1 = Range("B1").Value
TextBox2.Value = Format(Range("B1"), "$###.00")
TextBox3 = Sheets("Sheet1").Range("B1").Text
TextBox4.Value = Format(Range("B1"), "$###.##")
TextBox5.Value = Format(Range("B1"), "$0,000.00")
End Sub
Reply With Quote
  #3  
Old 04-17-2012, 01:23 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline Number format in Textbox on userform Windows 7 32bit Number format in Textbox on userform Office 2010 32bit
Expert
 
Join Date: Jan 2011
Location: UK
Posts: 369
Colin Legg will become famous soon enough
Default

Textboxes contain string data types. If your users are entering numbers then you can explicitly convert the string into a number (numbers in worksheets are always double data types), for example:
Code:
Private Sub TextBox1_Change()
    Sheets("Sheet1").Range("B25").Value = CDbl(Me.TextBox1.Value)
End Sub
or
Code:
 
Private Sub TextBox1_Change()
    Sheets("Sheet1").Range("B25").Value = Val(Me.TextBox1.Value)
End Sub
If that's what you need then you need to be very careful about what the user may enter into the textbox. You might want to research restricting the characters the user can use to 0 through to 9.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Number Format for Chart deadrxn24 Word 4 03-18-2012 05:38 PM
Number format in Textbox on userform custom number format: change thousands separator Ward Excel 1 06-07-2011 08:18 PM
Textbox Number changes when I open Word t0m46 Word VBA 0 09-07-2010 05:46 AM
Numbering, defining new number format nrschmid Word 0 12-30-2009 03:04 PM
Number format in Textbox on userform Default Number Format boutells Excel 1 05-20-2009 02:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft