Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Text Box Format

Thanks for the help guys. I have used Robert's code and it works fine except
for when the text box value = "", then I get a type mismatch error. Any
suggestions how to prevent this from happening?

Regards
Greg

"Robert Bradshaw" wrote in message
...
gregork wrote:
I have a textbox on a user form that displays data from a worksheet. How

can
I format the text box so that it only displays a number to 2 decimal

places?

Cheers
Greg


or in the lostfocus code for the textbox:

Private Sub TextBox1_LostFocus()
TextBox1.Value = Round(TextBox1.Value, 2)
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Text Box Format

How about something like:

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
If IsNumeric(.Value) Then
.Value = Round(.Value, 2)
Else
.Value = "Numeric Please"
.SelStart = 0
.SelLength = Len(.Value)
Beep
Cancel = True
End If
End With
End Sub


gregork wrote:

Thanks for the help guys. I have used Robert's code and it works fine except
for when the text box value = "", then I get a type mismatch error. Any
suggestions how to prevent this from happening?

Regards
Greg

"Robert Bradshaw" wrote in message
...
gregork wrote:
I have a textbox on a user form that displays data from a worksheet. How

can
I format the text box so that it only displays a number to 2 decimal

places?

Cheers
Greg


or in the lostfocus code for the textbox:

Private Sub TextBox1_LostFocus()
TextBox1.Value = Round(TextBox1.Value, 2)
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Text Box Format

Thanks Dave. Problem solved.

Cheers
Greg

"Dave Peterson" wrote in message
...
How about something like:

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
If IsNumeric(.Value) Then
.Value = Round(.Value, 2)
Else
.Value = "Numeric Please"
.SelStart = 0
.SelLength = Len(.Value)
Beep
Cancel = True
End If
End With
End Sub


gregork wrote:

Thanks for the help guys. I have used Robert's code and it works fine

except
for when the text box value = "", then I get a type mismatch error. Any
suggestions how to prevent this from happening?

Regards
Greg

"Robert Bradshaw" wrote in message
...
gregork wrote:
I have a textbox on a user form that displays data from a worksheet.

How
can
I format the text box so that it only displays a number to 2 decimal

places?

Cheers
Greg


or in the lostfocus code for the textbox:

Private Sub TextBox1_LostFocus()
TextBox1.Value = Round(TextBox1.Value, 2)
End Sub


--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with converting CUSTOM format/TEXT format to DATE format Deo Cleto Excel Worksheet Functions 6 June 2nd 09 08:14 PM
Change Date Format to Specific Text Format When Copying [email protected] Excel Discussion (Misc queries) 4 December 23rd 08 03:43 PM
Convert numbers from text format to number format merlin68 Excel Discussion (Misc queries) 7 June 20th 07 07:03 PM
Change number (in text format) to numeric format Pam Excel Discussion (Misc queries) 5 October 24th 05 07:45 PM
how to format excel format to text format with separator "|" in s. azlan New Users to Excel 1 January 31st 05 12:57 PM


All times are GMT +1. The time now is 07:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"