Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Formatting for Numbers & Currency in textbox


Hi all,

I was trying to make it easy for users too enter numbers and currency
on a userform by formatting as they entered. The effect is to insert
commas at the thousand marks (e.g: $ 1,000,000). Otherwise it is
difficult to read the numbers.

In a textbox alled t_salary we had the following code:

Private Sub t_salary_Change()

t_salary.Value = Format(t_salary.Value, "$#,##0")

End Sub

This appeared to work however when a certain amount of memory was used
(or when the PC felt like it) this created an infinite loop. When you
look at it that makes sense that it loops (the change in format sets
off the change event). Interestly when you step through it does not
loop.

You can format on the exit (or some other event) but the idea was to
assist with ENTRY of the large numbers.

Any ideas??

Cheers
Dug


---
~~ Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 473
Default Formatting for Numbers & Currency in textbox

Dugless wrote:
Private Sub t_salary_Change()

t_salary.Value = Format(t_salary.Value, "$#,##0")

End Sub

This appeared to work however when a certain amount of memory was used
(or when the PC felt like it) this created an infinite loop


Try this

Dim ItsMe As Boolean ' at top of module

Private Sub t_salary_Change()
If ItsMe Then Exit Sub
ItsMe = True
t_salary.Value = Format(t_salary.Value, "$#,##0")
ItsMe = False
End Sub


Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Formatting for Numbers & Currency in textbox

Hi Dugless,


This appeared to work however when a certain amount of memory was used
(or when the PC felt like it) this created an infinite loop. When you
look at it that makes sense that it loops (the change in format sets
off the change event). Interestly when you step through it does not
loop.

You can format on the exit (or some other event) but the idea was to
assist with ENTRY of the large numbers.

Any ideas??


Declare a variable at the top of the form's module:

Dim bDisableEvents as Boolean

Now in your change event:

Private Sub t_salary_Change()
If bDisableEvents Then Exit Sub
bDisableEvents=True
t_salary.Value = Format(t_salary.Value, "$#,##0")
bDisableEvents=False
End Sub


Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com

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
TextBox on a userform - format to currency & percent Terry Excel Discussion (Misc queries) 2 September 12th 08 02:46 PM
Textbox Formatting jmc8355 Excel Discussion (Misc queries) 3 April 24th 07 06:30 PM
TextBox Formatting grahammal Excel Discussion (Misc queries) 3 April 12th 06 04:54 PM
Userform Textbox Currency Format Problems Dunce in SC Excel Programming 2 October 27th 03 12:45 AM
Textbox on a userform.. dispaly as currency John Wilson Excel Programming 0 September 10th 03 10:54 PM


All times are GMT +1. The time now is 10:13 AM.

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"