From: Brad on
Thanks for taking the time to read my question.

I'm passing a string that is a cell reference to a function. In that
function I want to determine if that cell reference is within a predetermined
range. Not sure how to do that. Right now I have:

Function CheckRange(TheSheet As String, TheCell As Range) As Boolean

If TheSheet = "Sheet1" Then
if TheCell In Range("B4:B30") then 'This line is red as it is incorrect
CheckRange = True
End If

What do I use instead of "In"?

Thanks,

Brad
From: Otto Moehrbach on
Brad
Use something like:
If Intersect(ThisRange, ThatRange) is Nothing Then
This says if ThisRange is NOT a part of ThatRange. If you want the
opposite, stick a Not in front of Intersect. HTH Otto

"Brad" <Brad(a)discussions.microsoft.com> wrote in message
news:69544E6A-F58D-41EF-9514-144A773A6FF9(a)microsoft.com...
> Thanks for taking the time to read my question.
>
> I'm passing a string that is a cell reference to a function. In that
> function I want to determine if that cell reference is within a
> predetermined
> range. Not sure how to do that. Right now I have:
>
> Function CheckRange(TheSheet As String, TheCell As Range) As Boolean
>
> If TheSheet = "Sheet1" Then
> if TheCell In Range("B4:B30") then 'This line is red as it is incorrect
> CheckRange = True
> End If
>
> What do I use instead of "In"?
>
> Thanks,
>
> Brad

From: Brad on
Found Answer Here

http://www.exceltip.com/st/Determine_if_a_cell_is_within_a_range_using_VBA_in_Microsoft_Excel/484.html


"Brad" wrote:

> Thanks for taking the time to read my question.
>
> I'm passing a string that is a cell reference to a function. In that
> function I want to determine if that cell reference is within a predetermined
> range. Not sure how to do that. Right now I have:
>
> Function CheckRange(TheSheet As String, TheCell As Range) As Boolean
>
> If TheSheet = "Sheet1" Then
> if TheCell In Range("B4:B30") then 'This line is red as it is incorrect
> CheckRange = True
> End If
>
> What do I use instead of "In"?
>
> Thanks,
>
> Brad