29. VBA Tips - Find Out If A Cell Is Within A Range

This tip is about finding out whether a cell is within a range.
- It's basic set theory... we use VBA's INTERSECT
What we want to write is some VBA code that tells us whether we have selected a cell within the data table:
Here's the code we use here:
Explanation
- Using Worksheet_SelectionChange we trap the event that the selection has been changed
- We then set a variable InRange to equal an object returned by the intersect function
- If the interset function doesn't find an intersect, it returns NOTHING
- We then check whether InRange is equal to NOTHING...
- If it is, the the user has not selected a cell within the range.
- If it's equal to something, then the range is within MyData
Download sheet to practise how to Find Out If A Cell Is Within A Range in Excel
Training Video on how to Find Out If A Cell Is Within A Range in Excel:
| Attachment | Size |
|---|---|
| find-out-if-a-cell-is-within-a-range.xls | 66 KB |
»
- Nick's blog
- Login or register to post comments
- 24558 reads

Recent comments
6 years 36 weeks ago
7 years 22 weeks ago
7 years 34 weeks ago
7 years 37 weeks ago
7 years 38 weeks ago
7 years 43 weeks ago
7 years 51 weeks ago
8 years 1 day ago
8 years 1 day ago
8 years 2 days ago