Determining Cell within Range

  • Thread starter Thread starter Pablo
  • Start date Start date
P

Pablo

I am needing to determine if a selected cell is within a certain range. Below
is something that I have tried, but it only returns a 400 error.

Sub FindRange()
Dim rngMyRange As Range

Set rngMyRange = Worksheets("Sheet1").Range(A1, G20)

If ActiveCell.Select = rngMyRange Then
MsgBox ("Good Job")
Else
MsgBox ("Out of Bounds")
End If

End Sub
 
hi
you are trying to set the activecell to equal an entire range.
try this
sub FindRange()
Dim rngMyRange As Range
Set rngMyRange = Worksheets("Sheet1").Range("A1:G20")
If Not Application.Intersect(ActiveCell, rngMyRange) Is Nothing Then
MsgBox ("Good Job")
Else
MsgBox ("Out of Bounds")
End If
End Sub

regards
FSt1
 

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

Back
Top