See if cell is in Range

B

Brad

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
 
O

Otto Moehrbach

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top