Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Decimal numbers not recognized as numbers

I have a userform with a TextBox that enters data into the active cell. I
have also a validation of the data to check that only numbers are entered.

Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox1) Then
MsgBox "Only numbers"
TextBox1 = vbNullString
Cancel = True
End If
End Sub

All this looks to work fine.

If the number entered is an integer the number is recognized as a number
(active cell is a part of SUM formula to verify this).
If the number in the TextBox1 is a decimal number like 123,45 (yes, I live
in a country that uses ,-comma as decimal symbol and regional settings
reflects this) the validation accept is as a number, but the active cell
does not see it as a number but as text (the SUM formula shows that it is
not seen as a number).
If I go to the spreadsheet, double click in the cell that contains 123,45
and then select another cell in the spreadsheet (make no changes to the
cell containing 123,45) THEN the spreadsheet recognize 123,45 as a number
and udates the result of the SUM formula.

I have tried to format the active cell after the number has been entered:

ActiveCell.NumberFormat = "# ##0.00;(# ##0.00)"

but this doesn't help.

All help will be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Decimal numbers not recognized as numbers

Stein,

Something to try, after verification of number...

Dim dblEntry as Double
...
dblEntry = CDbl(TextBox1.Value)
ActiveCell.Value = dblEntry

Regards,
Jim Cone
San Francisco, USA


"Stein Kristiansen" wrote in message
...
I have a userform with a TextBox that enters data into the active cell. I
have also a validation of the data to check that only numbers are entered.

Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox1) Then
MsgBox "Only numbers"
TextBox1 = vbNullString
Cancel = True
End If
End Sub


All this looks to work fine.
If the number entered is an integer the number is recognized as a number
(active cell is a part of SUM formula to verify this).
If the number in the TextBox1 is a decimal number like 123,45 (yes, I live
in a country that uses ,-comma as decimal symbol and regional settings
reflects this) the validation accept is as a number, but the active cell
does not see it as a number but as text (the SUM formula shows that it is
not seen as a number).
If I go to the spreadsheet, double click in the cell that contains 123,45
and then select another cell in the spreadsheet (make no changes to the
cell containing 123,45) THEN the spreadsheet recognize 123,45 as a number
and udates the result of the SUM formula.
I have tried to format the active cell after the number has been entered:
ActiveCell.NumberFormat = "# ##0.00;(# ##0.00)"
but this doesn't help.
All help will be appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Decimal numbers not recognized as numbers

Since Jim says something to try, perhaps some added.

cdbl should convert the number with respect to your regional settings.

When you let excel do the conversion implicitly as you do now (all entries
in a textbox are text), then it is interpreted as if it is a US English
value. It is put in the cell as Text. then when you edit the cell, it is
re-evaluated and converted to a number. Applying a number format to text
(as you have tried) does not convert what is stored there.

Stephen Bullen has graciously put his chapter on dealing with international
issues online:
http://www.oaltd.co.uk/ExcelProgRef/Ch22/default.htm

from his book:
Excel 2002 VBA Programmer's Reference

Written by John Green, Stephen Bullen, Rob Bovey and Robert Rosenberg
Published by Wrox Press, November 2001
ISBN: 0764543717


You might find this online resource an excellent reference when dealing with
these problems.

--
Regards,
Tom Ogilvy


"Jim Cone" wrote in message
...
Stein,

Something to try, after verification of number...

Dim dblEntry as Double
...
dblEntry = CDbl(TextBox1.Value)
ActiveCell.Value = dblEntry

Regards,
Jim Cone
San Francisco, USA


"Stein Kristiansen" wrote in message
...
I have a userform with a TextBox that enters data into the active cell.

I
have also a validation of the data to check that only numbers are

entered.

Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox1) Then
MsgBox "Only numbers"
TextBox1 = vbNullString
Cancel = True
End If
End Sub


All this looks to work fine.
If the number entered is an integer the number is recognized as a number
(active cell is a part of SUM formula to verify this).
If the number in the TextBox1 is a decimal number like 123,45 (yes, I

live
in a country that uses ,-comma as decimal symbol and regional settings
reflects this) the validation accept is as a number, but the active cell
does not see it as a number but as text (the SUM formula shows that it

is
not seen as a number).
If I go to the spreadsheet, double click in the cell that contains

123,45
and then select another cell in the spreadsheet (make no changes to the
cell containing 123,45) THEN the spreadsheet recognize 123,45 as a

number
and udates the result of the SUM formula.
I have tried to format the active cell after the number has been

entered:
ActiveCell.NumberFormat = "# ##0.00;(# ##0.00)"
but this doesn't help.
All help will be appreciated.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Decimal numbers not recognized as numbers

Dear Jim and Tom,

You saved my day!!! Cdbl fixes my problem. Thanks for the link to the web
page discussing international problems, I think I'll have to read it
several times to fully understand all the aspects.

Regards
Stein

On Sun, 13 Feb 2005 09:54:04 -0500, Tom Ogilvy wrote:

Since Jim says something to try, perhaps some added.

cdbl should convert the number with respect to your regional settings.

When you let excel do the conversion implicitly as you do now (all
entries
in a textbox are text), then it is interpreted as if it is a US English
value. It is put in the cell as Text. then when you edit the cell, it
is
re-evaluated and converted to a number. Applying a number format to text
(as you have tried) does not convert what is stored there.

Stephen Bullen has graciously put his chapter on dealing with
international
issues online:
http://www.oaltd.co.uk/ExcelProgRef/Ch22/default.htm

from his book:
Excel 2002 VBA Programmer's Reference

Written by John Green, Stephen Bullen, Rob Bovey and Robert Rosenberg
Published by Wrox Press, November 2001
ISBN: 0764543717


You might find this online resource an excellent reference when dealing
with
these problems.


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 to use numbers to right of decimal only rudyeb Excel Discussion (Misc queries) 2 October 1st 08 04:46 PM
Decimal Numbers typed into Excel 2003 read as whole numbers john mcmichael Excel Discussion (Misc queries) 1 May 10th 07 08:18 PM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM
How can I sort mostly 3 decimal with some 4 decimal numbers PeterM Excel Discussion (Misc queries) 4 August 16th 06 02:15 AM
Text strings recognized as numbers given different regional settin Anders Excel Programming 0 September 8th 04 11:03 PM


All times are GMT +1. The time now is 11:14 AM.

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"