View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
John Wirt[_4_] John Wirt[_4_] is offline
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