Determining Cell within Range
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 |
Determining Cell within Range
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 "Pablo" wrote: 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 |
All times are GMT +1. The time now is 03:34 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com