Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jdj jdj is offline
external usenet poster
 
Posts: 2
Default decimals in textboxes

I am trying to limit the decimals in a textbox to 2 can
anyone help me with this ? the fixeddecimals etc. does
not work.

Thanks

JdJ
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default decimals in textboxes

JdJ

many hours have been spent by programmers because MS was too lazy to
implement a few often needed properties to the textbox object in msforms.

shall we say it allows for flexibility?


Following works for me (Excel97+), also with non-english regional settings

Option Explicit

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii.Value = FilterInput(TextBox1.Text, KeyAscii.Value)
End Sub

Function FilterInput(s As String, ByVal k As Integer) As Integer
Dim sDec As String, sKey As String, number As Variant

On Error GoTo TheEnd
With Application
sDec = .International(xlDecimalSeparator)
#If VBA6 Then
If Not .UseSystemSeparators Then sDec = .DecimalSeparator
#End If
End With

sKey = Chr(k)
If sKey = "." And sKey < sDec Then sKey = sDec

If s = "" And (sKey = "-" Or sKey = sDec) Then
FilterInput = Asc(sKey)
ElseIf sKey Like "[0123456789" & sDec & "]" Then
number = CDec(s & sKey)
If number = WorksheetFunction.Round(number, 2) Then
FilterInput = Asc(sKey)
End If
End If
TheEnd:
End Function


cheerz!



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"jdj" wrote:

I am trying to limit the decimals in a textbox to 2 can
anyone help me with this ? the fixeddecimals etc. does
not work.

Thanks

JdJ


  #3   Report Post  
Posted to microsoft.public.excel.programming
jdj jdj is offline
external usenet poster
 
Posts: 2
Default decimals in textboxes

Hi keepITcool

Tried it, but still no results.
Thanks anyway !!

JdJ
-----Original Message-----
JdJ

many hours have been spent by programmers because MS was

too lazy to
implement a few often needed properties to the textbox

object in msforms.

shall we say it allows for flexibility?


Following works for me (Excel97+), also with non-english

regional settings

Option Explicit

Private Sub TextBox1_KeyPress(ByVal KeyAscii As

MSForms.ReturnInteger)
KeyAscii.Value = FilterInput(TextBox1.Text,

KeyAscii.Value)
End Sub

Function FilterInput(s As String, ByVal k As Integer) As

Integer
Dim sDec As String, sKey As String, number As Variant

On Error GoTo TheEnd
With Application
sDec = .International(xlDecimalSeparator)
#If VBA6 Then
If Not .UseSystemSeparators Then sDec

= .DecimalSeparator
#End If
End With

sKey = Chr(k)
If sKey = "." And sKey < sDec Then sKey = sDec

If s = "" And (sKey = "-" Or sKey = sDec) Then
FilterInput = Asc(sKey)
ElseIf sKey Like "[0123456789" & sDec & "]" Then
number = CDec(s & sKey)
If number = WorksheetFunction.Round(number, 2) Then
FilterInput = Asc(sKey)
End If
End If
TheEnd:
End Function


cheerz!



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"jdj" wrote:

I am trying to limit the decimals in a textbox to 2

can
anyone help me with this ? the fixeddecimals etc. does
not work.

Thanks

JdJ


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default decimals in textboxes

are u working with an embedded control or a textbox on a userform?

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"JdJ" wrote:

Hi keepITcool

Tried it, but still no results.
Thanks anyway !!

JdJ

  #5   Report Post  
Posted to microsoft.public.excel.programming
JdJ JdJ is offline
external usenet poster
 
Posts: 4
Default decimals in textboxes

Userform.

Johann
-----Original Message-----
are u working with an embedded control or a textbox on a

userform?

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"JdJ" wrote:

Hi keepITcool

Tried it, but still no results.
Thanks anyway !!

JdJ

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default decimals in textboxes


check the sequence of any other eventshandlers running on the box?
no conflicts there?

Set breakpoints to see where the code exits (and if it gets there in the
first place).
Preferably use e few debug.print lines : This proc works with keyboard
buffer. Using mouse in VBE is okay but typing (editing) will interfere
with that buffer.


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"JdJ" wrote:

Userform.

Johann
-----Original Message-----
are u working with an embedded control or a textbox on a

userform?

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"JdJ" wrote:

Hi keepITcool

Tried it, but still no results.
Thanks anyway !!

JdJ

.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default decimals in textboxes

While you'r helping me, and I am grateful for your
effort, I have another problem ;

Activating a form that contains multipages, how can I get
the first page to always show?
It normally opens the page where you exited.

Thanks again Maistro !

Johann
-----Original Message-----
are u working with an embedded control or a textbox on a

userform?

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"JdJ" wrote:

Hi keepITcool

Tried it, but still no results.
Thanks anyway !!

JdJ

.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default decimals in textboxes


multipage1.value=1

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Johann" wrote:

While you'r helping me, and I am grateful for your
effort, I have another problem ;

Activating a form that contains multipages, how can I get
the first page to always show?
It normally opens the page where you exited.

Thanks again Maistro !

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
Count digits before decimals and after decimals Elton Law[_2_] Excel Worksheet Functions 5 April 3rd 23 10:59 AM
Textboxes SAL Excel Discussion (Misc queries) 2 July 13th 07 12:24 AM
UserForm TextBoxes Rob Excel Discussion (Misc queries) 2 August 6th 05 03:07 AM
tab between several textboxes Kim Excel Worksheet Functions 0 May 9th 05 04:08 PM
Referencing Textboxes? Jeff Excel Discussion (Misc queries) 4 March 30th 05 04:14 AM


All times are GMT +1. The time now is 03:48 PM.

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

About Us

"It's about Microsoft Excel"