Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Why is this a number?

Hi
I'm using VBA 6.3

If I pass 45- to this:

If IsNumeric(OffsetNo) = False Then
...

it returns True.

1) Why?

2) How do I prevent this happening?

Thanks in Advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why is this a number?

Because Excel knows how to convert it to a number

? clng("45-")
-45

which is the defninition of isNumeric.

Many accounting applications indicate negatives by using the notation you
show.

--
Regards,
Tom Ogilvy

"Dave F." wrote in message
...
Hi
I'm using VBA 6.3

If I pass 45- to this:

If IsNumeric(OffsetNo) = False Then
...

it returns True.

1) Why?

2) How do I prevent this happening?

Thanks in Advance.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Why is this a number?

Thanks for replying.


I'm running this within AutoCAD & don't have the Office Reference ticked.
I'm confused why it would be a specific Excel problem.
Isn't IsNumeric a general VB command?

Is there a way to prevent it happening?

I'm trying to allow only positive numeric values being typed & displayed in
a textbox:

If IsNumeric(OffsetNo) = False Then ' if there is a value in the
textbox & it's not a number
OffsetNo = Left$(OffsetNo, Len(OffsetNo) - 1) ' remove last typed
TxtBx_Dist.Value = OffsetNo ' & put it back in the box
End If

Cheers

Dave F.


"Tom Ogilvy" wrote in message
...
Because Excel knows how to convert it to a number

? clng("45-")
-45

which is the defninition of isNumeric.

Many accounting applications indicate negatives by using the notation you
show.

--
Regards,
Tom Ogilvy

"Dave F." wrote in message
...
Hi
I'm using VBA 6.3

If I pass 45- to this:

If IsNumeric(OffsetNo) = False Then
...

it returns True.

1) Why?

2) How do I prevent this happening?

Thanks in Advance.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why is this a number?

I don't recall saying it is a specific Excel problem - Perhaps I should have
said VBA rather than Excel. Neither clng or IsNumeric are unique to excel.

If you want to check for a hypen as the last character, then check if a
hypen is the last character.

Another approach might be

if isnumeric(string) then
if clng(string) < 0 then



--
Regards,
Tom Ogilvy


"Dave F." wrote in message
...
Thanks for replying.


I'm running this within AutoCAD & don't have the Office Reference ticked.
I'm confused why it would be a specific Excel problem.
Isn't IsNumeric a general VB command?

Is there a way to prevent it happening?

I'm trying to allow only positive numeric values being typed & displayed

in
a textbox:

If IsNumeric(OffsetNo) = False Then ' if there is a value in the
textbox & it's not a number
OffsetNo = Left$(OffsetNo, Len(OffsetNo) - 1) ' remove last typed
TxtBx_Dist.Value = OffsetNo ' & put it back in the box
End If

Cheers

Dave F.


"Tom Ogilvy" wrote in message
...
Because Excel knows how to convert it to a number

? clng("45-")
-45

which is the defninition of isNumeric.

Many accounting applications indicate negatives by using the notation

you
show.

--
Regards,
Tom Ogilvy

"Dave F." wrote in message
...
Hi
I'm using VBA 6.3

If I pass 45- to this:

If IsNumeric(OffsetNo) = False Then
...

it returns True.

1) Why?

2) How do I prevent this happening?

Thanks in Advance.








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
Sumif number is greater than a number but less than another number lulu151 Excel Discussion (Misc queries) 2 May 7th 10 07:12 PM
How can I click on a telephone number in an Excel 2002 spreadsheet, and have the number dialed? jbclem Excel Discussion (Misc queries) 2 August 13th 09 01:57 AM
How to calculate number of occurencies of a specific number number Stefan Excel Discussion (Misc queries) 4 September 8th 08 08:33 AM
countif formula to find the occurances of a number that is greater than one number but less than another steveo Excel Discussion (Misc queries) 3 July 8th 06 02:04 AM
Rounding a number to a multiple quantity that adds to a fixed total number wjlo Excel Worksheet Functions 1 November 9th 04 04:43 PM


All times are GMT +1. The time now is 03:08 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"