Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Helpneeded in writing special function, "IsBetween"

I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1, and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Helpneeded in writing special function, "IsBetween"

John,

Your missing an End If

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End If 'MISSING
End Function

Dan E

"John Wirt" wrote in message ...
I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1, and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Helpneeded in writing special function, "IsBetween"

John,

Why use VBA when you can do it with a worksheet function

=IF(OR(AND(A1B1,A1<C1),AND(A1<B1,A1C1)),"Yes","N o")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1,

and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Helpneeded in writing special function, "IsBetween"

Unless your Personal.xls is an add-in, you need to explicitly
reference Personal.xls:

=Personal.xls!IsBetween(A1,B1,C1)

You also had an Endi If missing.


In article ,
"John Wirt" wrote:

I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1, and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Helpneeded in writing special function, "IsBetween"

Bob - that doesn't do what the OP's function does when A1=B1 or
A1=C1. One alternative:

=IF(OR(A1=B1,A1=C1),"",IF(AND(A1B1,A1<C1),"Yes"," No"))

In article ,
"Bob Phillips" wrote:

John,

Why use VBA when you can do it with a worksheet function

=IF(OR(AND(A1B1,A1<C1),AND(A1<B1,A1C1)),"Yes","N o")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1,

and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Helpneeded in writing special function, "IsBetween"

Function IsBetween(cell1, cell2, cell3) As String
IsBetween = _
IIf((cell1 cell2 And cell1 < cell3) Or _
(cell1 cell3 And cell1 < cell2), "Yes", "No")
End Function

--
Regards,
Tom Ogilvy



"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1,

and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Helpneeded in writing special function, "IsBetween"

How do I make Personal.xls an Add-in? Thanks.

John

"J.E. McGimpsey" wrote in message
...
Unless your Personal.xls is an add-in, you need to explicitly
reference Personal.xls:

=Personal.xls!IsBetween(A1,B1,C1)

You also had an Endi If missing.


In article ,
"John Wirt" wrote:

I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1,

and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Helpneeded in writing special function, "IsBetween"

Because I get tired of typing this long formula in and changing the cell
address many times. Block copy won't work in my sitiuation.
"Bob Phillips" wrote in message
...
John,

Why use VBA when you can do it with a worksheet function

=IF(OR(AND(A1B1,A1<C1),AND(A1<B1,A1C1)),"Yes","N o")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1,

and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Helpneeded in writing special function, "IsBetween"

Oops - dropped the rest of your function:

=IF(OR(A1=B1,A1=C1),"",IF(OR(AND(A1B1,A1<C1),AND( A1<B1,A1C1)),
"Yes","No"))


In article
,
"J.E. McGimpsey" wrote:

Bob - that doesn't do what the OP's function does when A1=B1 or
A1=C1. One alternative:

=IF(OR(A1=B1,A1=C1),"",IF(AND(A1B1,A1<C1),"Yes"," No"))

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Helpneeded in writing special function, "IsBetween"

select it in the project explorer and select ThisWorkbook. Then go to the
properties window and select the isaddin property and set it to true.

--
Regards,
Tom Ogilvy

"John Wirt" wrote in message
...
How do I make Personal.xls an Add-in? Thanks.

John

"J.E. McGimpsey" wrote in message
...
Unless your Personal.xls is an add-in, you need to explicitly
reference Personal.xls:

=Personal.xls!IsBetween(A1,B1,C1)

You also had an Endi If missing.


In article ,
"John Wirt" wrote:

I want to write a VBA function that compares the numeric values in

cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1,

B1,
and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt








  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Helpneeded in writing special function, "IsBetween"

JE,

You're right of course, but I find it difficult to believe that the OP wants
to show a blank if A1 is on one of the boundaries. I may be (probably am?)
wrong, but I would venture that it is a case that he didn't think of all the
possibilities as you did.

Regards

Bob

"J.E. McGimpsey" wrote in message
...
Bob - that doesn't do what the OP's function does when A1=B1 or
A1=C1. One alternative:

=IF(OR(A1=B1,A1=C1),"",IF(AND(A1B1,A1<C1),"Yes"," No"))

In article ,
"Bob Phillips" wrote:

John,

Why use VBA when you can do it with a worksheet function

=IF(OR(AND(A1B1,A1<C1),AND(A1<B1,A1C1)),"Yes","N o")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in

cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1,

B1,
and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt






  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Helpneeded in writing special function, "IsBetween"

It works, lads. Thank you.

Will be used a lot in checking statistical tables for the National Center
for Education Statistics.

John


"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1,

and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt




  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Helpneeded in writing special function, "IsBetween"

You're right, I didn't think of the boundaries. I wnat the function to show
"Err? if any of the entries are equal (exactly equal), so I've added that to
function.

John


"Bob Phillips" wrote in message
...
JE,

You're right of course, but I find it difficult to believe that the OP

wants
to show a blank if A1 is on one of the boundaries. I may be (probably am?)
wrong, but I would venture that it is a case that he didn't think of all

the
possibilities as you did.

Regards

Bob

"J.E. McGimpsey" wrote in message
...
Bob - that doesn't do what the OP's function does when A1=B1 or
A1=C1. One alternative:

=IF(OR(A1=B1,A1=C1),"",IF(AND(A1B1,A1<C1),"Yes"," No"))

In article ,
"Bob Phillips" wrote:

John,

Why use VBA when you can do it with a worksheet function

=IF(OR(AND(A1B1,A1<C1),AND(A1<B1,A1C1)),"Yes","N o")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in

cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is
between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the
function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1,

B1,
and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt








  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Helpneeded in writing special function, "IsBetween"

Yes, this is a bit slicker.

John


"Tom Ogilvy" wrote in message
...
Function IsBetween(cell1, cell2, cell3) As String
IsBetween = _
IIf((cell1 cell2 And cell1 < cell3) Or _
(cell1 cell3 And cell1 < cell2), "Yes", "No")
End Function

--
Regards,
Tom Ogilvy



"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1,

and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt






  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Helpneeded in writing special function, "IsBetween"

John,

Why do you need to keep typing it? Copy/paste will update the references to
relative to the target cell.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
Because I get tired of typing this long formula in and changing the cell
address many times. Block copy won't work in my sitiuation.
"Bob Phillips" wrote in message
...
John,

Why use VBA when you can do it with a worksheet function

=IF(OR(AND(A1B1,A1<C1),AND(A1<B1,A1C1)),"Yes","N o")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in

cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1,

B1,
and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt










  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Helpneeded in writing special function, "IsBetween"

I started out using this function and found that I was spending most of my
time getting just the right columns in the formula every place I need it.
The columns are not always adjacent to each other.

Sometimes a VBA function is better.

John

"Bob Phillips" wrote in message
...
John,

Why use VBA when you can do it with a worksheet function

=IF(OR(AND(A1B1,A1<C1),AND(A1<B1,A1C1)),"Yes","N o")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
I want to write a VBA function that compares the numeric values in cell1
against the value is cell2 and cell 3, and reports "Yes" if cell1 is

between
cell2 and cell 3, and otherwise "No." Here is a cut & paste of the

function
I;ve written in PERSONAL.XLS (see below).

WHen I enter =IsBetween(A1, B1,C1) in D1 with numeric values in A1, B1,

and
C1 I get a #NAME error in D1. How come?

Function IsBetween(cell1, cell2, cell3) As String
If cell1 cell2 Then
If cell1 < cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
ElseIf cell1 < cell2 Then
If cell1 cell3 Then
IsBetween = "Yes"
Else
IsBetween = "No"
End If
End Function


Thanks.

John Wirt






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
Text "comparison" operator for "contains" used in an "IF" Function Pawaso Excel Worksheet Functions 4 April 4th 23 11:35 AM
Office 2007 "go to special" shortcut function Michele Excel Discussion (Misc queries) 5 August 5th 09 06:24 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Writing "shapes" to disk file Peter Spencer Excel Programming 0 September 9th 03 10:11 AM
"Small" Multi-Dimensional Array Slow Writing To Cell Steve Hieb Excel Programming 2 September 6th 03 03:20 AM


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