Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Creating a MyIsEven function

I have a workbook that uses the ISEVEN function. Since some people who use
the workbook may not have ATP installed, I decided to try writing my own
MyIsEven function. It gives the same result as ISEVEN on all of the test
entries I tried, except for numbers greater than 2,147,483,647.

Function MyIsEven(Num As Long) As Boolean
Select Case Right (Num, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function

I thought of adding an If statement to deal with the large numbers, but it
didn't make any difference:
If Num 2147483647 Then
Num = Num - 2147483646
End If

I also thought of using MyIsEven(Num As Double), but that introduces
different errors.

For my workbook, what I have will work fine, but I thought I would try to be
as thorough as possible.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Creating a MyIsEven function

Make the argument a string rather than a number:

Function MyIsEven(r As Range) As Boolean
Dim s As String
s = r.Value
Select Case Right(s, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function
--
Gary''s Student - gsnu200908


"Horatio J. Bilge, Jr." wrote:

I have a workbook that uses the ISEVEN function. Since some people who use
the workbook may not have ATP installed, I decided to try writing my own
MyIsEven function. It gives the same result as ISEVEN on all of the test
entries I tried, except for numbers greater than 2,147,483,647.

Function MyIsEven(Num As Long) As Boolean
Select Case Right (Num, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function

I thought of adding an If statement to deal with the large numbers, but it
didn't make any difference:
If Num 2147483647 Then
Num = Num - 2147483646
End If

I also thought of using MyIsEven(Num As Double), but that introduces
different errors.

For my workbook, what I have will work fine, but I thought I would try to be
as thorough as possible.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Creating a MyIsEven function

To emulate the ATP ISEVEN then the value needs to be truncated

s = Int(r.Value)

Mike

"Gary''s Student" wrote:

Make the argument a string rather than a number:

Function MyIsEven(r As Range) As Boolean
Dim s As String
s = r.Value
Select Case Right(s, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function
--
Gary''s Student - gsnu200908


"Horatio J. Bilge, Jr." wrote:

I have a workbook that uses the ISEVEN function. Since some people who use
the workbook may not have ATP installed, I decided to try writing my own
MyIsEven function. It gives the same result as ISEVEN on all of the test
entries I tried, except for numbers greater than 2,147,483,647.

Function MyIsEven(Num As Long) As Boolean
Select Case Right (Num, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function

I thought of adding an If statement to deal with the large numbers, but it
didn't make any difference:
If Num 2147483647 Then
Num = Num - 2147483646
End If

I also thought of using MyIsEven(Num As Double), but that introduces
different errors.

For my workbook, what I have will work fine, but I thought I would try to be
as thorough as possible.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Creating a MyIsEven function

That solves the problem of the big numbers, but it introduces other errors.
Here are some samples:

Value MyIsEven ISEVEN
1.2 TRUE FALSE
abc2 TRUE #VALUE!
two FALSE #VALUE!
[blank] FALSE TRUE

"Gary''s Student" wrote:

Make the argument a string rather than a number:

Function MyIsEven(r As Range) As Boolean
Dim s As String
s = r.Value
Select Case Right(s, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function
--
Gary''s Student - gsnu200908


"Horatio J. Bilge, Jr." wrote:

I have a workbook that uses the ISEVEN function. Since some people who use
the workbook may not have ATP installed, I decided to try writing my own
MyIsEven function. It gives the same result as ISEVEN on all of the test
entries I tried, except for numbers greater than 2,147,483,647.

Function MyIsEven(Num As Long) As Boolean
Select Case Right (Num, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function

I thought of adding an If statement to deal with the large numbers, but it
didn't make any difference:
If Num 2147483647 Then
Num = Num - 2147483646
End If

I also thought of using MyIsEven(Num As Double), but that introduces
different errors.

For my workbook, what I have will work fine, but I thought I would try to be
as thorough as possible.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Creating a MyIsEven function

Read my reply. The ISEVEN function truncates decimals before testing for even

Mike

"Horatio J. Bilge, Jr." wrote:

That solves the problem of the big numbers, but it introduces other errors.
Here are some samples:

Value MyIsEven ISEVEN
1.2 TRUE FALSE
abc2 TRUE #VALUE!
two FALSE #VALUE!
[blank] FALSE TRUE

"Gary''s Student" wrote:

Make the argument a string rather than a number:

Function MyIsEven(r As Range) As Boolean
Dim s As String
s = r.Value
Select Case Right(s, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function
--
Gary''s Student - gsnu200908


"Horatio J. Bilge, Jr." wrote:

I have a workbook that uses the ISEVEN function. Since some people who use
the workbook may not have ATP installed, I decided to try writing my own
MyIsEven function. It gives the same result as ISEVEN on all of the test
entries I tried, except for numbers greater than 2,147,483,647.

Function MyIsEven(Num As Long) As Boolean
Select Case Right (Num, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function

I thought of adding an If statement to deal with the large numbers, but it
didn't make any difference:
If Num 2147483647 Then
Num = Num - 2147483646
End If

I also thought of using MyIsEven(Num As Double), but that introduces
different errors.

For my workbook, what I have will work fine, but I thought I would try to be
as thorough as possible.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Creating a MyIsEven function

That works on all of my samples, except for negative decimals. I changed it to:
s = Fix(r.Value) and it seems to work great.

Thanks!

"Mike H" wrote:

To emulate the ATP ISEVEN then the value needs to be truncated

s = Int(r.Value)

Mike

"Gary''s Student" wrote:

Make the argument a string rather than a number:

Function MyIsEven(r As Range) As Boolean
Dim s As String
s = r.Value
Select Case Right(s, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function
--
Gary''s Student - gsnu200908


"Horatio J. Bilge, Jr." wrote:

I have a workbook that uses the ISEVEN function. Since some people who use
the workbook may not have ATP installed, I decided to try writing my own
MyIsEven function. It gives the same result as ISEVEN on all of the test
entries I tried, except for numbers greater than 2,147,483,647.

Function MyIsEven(Num As Long) As Boolean
Select Case Right (Num, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function

I thought of adding an If statement to deal with the large numbers, but it
didn't make any difference:
If Num 2147483647 Then
Num = Num - 2147483646
End If

I also thought of using MyIsEven(Num As Double), but that introduces
different errors.

For my workbook, what I have will work fine, but I thought I would try to be
as thorough as possible.

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Creating a MyIsEven function

Good point, INT rounds the 'wrong' way for your purposes

Mike

"Horatio J. Bilge, Jr." wrote:

That works on all of my samples, except for negative decimals. I changed it to:
s = Fix(r.Value) and it seems to work great.

Thanks!

"Mike H" wrote:

To emulate the ATP ISEVEN then the value needs to be truncated

s = Int(r.Value)

Mike

"Gary''s Student" wrote:

Make the argument a string rather than a number:

Function MyIsEven(r As Range) As Boolean
Dim s As String
s = r.Value
Select Case Right(s, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function
--
Gary''s Student - gsnu200908


"Horatio J. Bilge, Jr." wrote:

I have a workbook that uses the ISEVEN function. Since some people who use
the workbook may not have ATP installed, I decided to try writing my own
MyIsEven function. It gives the same result as ISEVEN on all of the test
entries I tried, except for numbers greater than 2,147,483,647.

Function MyIsEven(Num As Long) As Boolean
Select Case Right (Num, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function

I thought of adding an If statement to deal with the large numbers, but it
didn't make any difference:
If Num 2147483647 Then
Num = Num - 2147483646
End If

I also thought of using MyIsEven(Num As Double), but that introduces
different errors.

For my workbook, what I have will work fine, but I thought I would try to be
as thorough as possible.

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Creating a MyIsEven function

It worked great in my test workbook, but when I put in into the actual
workbook, I got an error. I think the error is because the value I am testing
is not a range.
=MyIsEven(COUNT(A1:G1)) -- gives #VALUE! error
=MyIsEven(2) -- also gives #VALUE! error


"Mike H" wrote:

Good point, INT rounds the 'wrong' way for your purposes

Mike

"Horatio J. Bilge, Jr." wrote:

That works on all of my samples, except for negative decimals. I changed it to:
s = Fix(r.Value) and it seems to work great.

Thanks!

"Mike H" wrote:

To emulate the ATP ISEVEN then the value needs to be truncated

s = Int(r.Value)

Mike

"Gary''s Student" wrote:

Make the argument a string rather than a number:

Function MyIsEven(r As Range) As Boolean
Dim s As String
s = r.Value
Select Case Right(s, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function
--
Gary''s Student - gsnu200908


"Horatio J. Bilge, Jr." wrote:

I have a workbook that uses the ISEVEN function. Since some people who use
the workbook may not have ATP installed, I decided to try writing my own
MyIsEven function. It gives the same result as ISEVEN on all of the test
entries I tried, except for numbers greater than 2,147,483,647.

Function MyIsEven(Num As Long) As Boolean
Select Case Right (Num, 1)
Case 0, 2, 4, 6, 8
MyIsEven = True
Case Else
MyIsEven = False
End Select
End Function

I thought of adding an If statement to deal with the large numbers, but it
didn't make any difference:
If Num 2147483647 Then
Num = Num - 2147483646
End If

I also thought of using MyIsEven(Num As Double), but that introduces
different errors.

For my workbook, what I have will work fine, but I thought I would try to be
as thorough as possible.

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
Help with creating a function Craig Excel Worksheet Functions 4 February 2nd 09 09:51 PM
Need help creating a function chrspty Excel Worksheet Functions 2 August 1st 08 04:48 PM
Creating a Function Stu Gnu[_2_] Excel Worksheet Functions 4 August 31st 07 08:44 AM
Creating a function BeginnerRick Excel Worksheet Functions 3 November 24th 06 09:12 PM
creating a function NeilPoehlmann Excel Discussion (Misc queries) 5 June 15th 05 08:08 PM


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