Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default Test for Decimal

In a section of code I am using the MOD function to test for cases where a
given number is a multiple of 51.

If Range("A1") MOD 51 = 0 then
....more code

In cell A1 I have 203.52. The function is returning true because the 203.52
is rounded up to 204 as part of the MOD test. I don't want to apply code to
A1l and need to test for the decimal before I use the MOD function, I think.

If Range("A1") < "decimal" then
If Range("A1") MOD 51 = 0 then
...more code

Is this the logic I need and how do I test for the decimal?

Thanks.

--
Ken Hudson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Test for Decimal

You can test your value like this...

If InStr(Range("A1") .Value, ".") = 0 Then
If Range("A1") MOD 51 = 0 then
...more code

Rick


"Ken Hudson" wrote in message
...
In a section of code I am using the MOD function to test for cases where a
given number is a multiple of 51.

If Range("A1") MOD 51 = 0 then
....more code

In cell A1 I have 203.52. The function is returning true because the
203.52
is rounded up to 204 as part of the MOD test. I don't want to apply code
to
A1l and need to test for the decimal before I use the MOD function, I
think.

If Range("A1") < "decimal" then
If Range("A1") MOD 51 = 0 then
...more code

Is this the logic I need and how do I test for the decimal?

Thanks.

--
Ken Hudson


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Test for Decimal

Here is two methods. either search for a decimal point in the number or use
Mod and test if the remainder equals 0.



If InStr(Range("J21").Text, ".") = 0 Then

End If

If (Range("J21") Mod 10) = 0 Then

End If


"Ken Hudson" wrote:

In a section of code I am using the MOD function to test for cases where a
given number is a multiple of 51.

If Range("A1") MOD 51 = 0 then
....more code

In cell A1 I have 203.52. The function is returning true because the 203.52
is rounded up to 204 as part of the MOD test. I don't want to apply code to
A1l and need to test for the decimal before I use the MOD function, I think.

If Range("A1") < "decimal" then
If Range("A1") MOD 51 = 0 then
...more code

Is this the logic I need and how do I test for the decimal?

Thanks.

--
Ken Hudson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default Test for Decimal

Thanks, Nigel.
I believe the correct expression for your side of the pond is "that works a
treat."
--
Ken Hudson


"Nigel" wrote:

I would take the integer value subtract from the original.

With Range("A1")
If .Value - Int(.Value) = 0 And .Value Mod 51 = 0 Then
'more code
End If
End With


--

Regards,
Nigel




"Ken Hudson" wrote in message
...
In a section of code I am using the MOD function to test for cases where a
given number is a multiple of 51.

If Range("A1") MOD 51 = 0 then
....more code

In cell A1 I have 203.52. The function is returning true because the
203.52
is rounded up to 204 as part of the MOD test. I don't want to apply code
to
A1l and need to test for the decimal before I use the MOD function, I
think.

If Range("A1") < "decimal" then
If Range("A1") MOD 51 = 0 then
...more code

Is this the logic I need and how do I test for the decimal?

Thanks.

--
Ken Hudson




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Test for Decimal

While it is probably not the case with the OP, just thought I would point
out that your Int function call will fail if the contents of A1 is a
non-number. Also, you could save a couple of characters by testing the
..Value=Int(.Value) directly instead of subtracting them and seeing if that
difference was zero.

Rick


"Nigel" wrote in message
...
I would take the integer value subtract from the original.

With Range("A1")
If .Value - Int(.Value) = 0 And .Value Mod 51 = 0 Then
'more code
End If
End With


--

Regards,
Nigel




"Ken Hudson" wrote in message
...
In a section of code I am using the MOD function to test for cases where
a
given number is a multiple of 51.

If Range("A1") MOD 51 = 0 then
....more code

In cell A1 I have 203.52. The function is returning true because the
203.52
is rounded up to 204 as part of the MOD test. I don't want to apply code
to
A1l and need to test for the decimal before I use the MOD function, I
think.

If Range("A1") < "decimal" then
If Range("A1") MOD 51 = 0 then
...more code

Is this the logic I need and how do I test for the decimal?

Thanks.

--
Ken Hudson



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
Logical test IF a decimal was typed in a cell jheath.bc Excel Worksheet Functions 8 April 22nd 23 04:07 AM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM
Batch converting CSV files from comma-decimal to period-decimal Nodles Excel Discussion (Misc queries) 3 July 5th 06 06:57 PM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Excel Discussion (Misc queries) 3 March 18th 06 06:20 PM
FIXED 2 DECIMAL PLACES, MUST ENTER ALL ZEROES AFTER DECIMAL POINT. SUKYKITTY Excel Discussion (Misc queries) 3 July 6th 05 01:50 PM


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