check an ective cell against a defined range

dyerstm

New Member
Joined
Sep 4, 2003
Messages
12
I have a sub routine that checks if the ActiveCell.Value is within a specified range(("A7:A46") but I cant get it to work, what I'm trying to do is ensure that when a user clicks my command button it checks the active cell and compares it to range("A7:A46")

I have something like this

Private Sumb Cmdbutton_Click()

if activeCell.value <> myRange("A7:A46")
...indicate error!

but I can't get it to work
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
To check if a cell is in a range try using Intersect.
Code:
If Not Intersect(ActiveCell, Range("A7:A46") Is Nothing Then
     ' active cell is in range so run code
Else
     ' active cell is not in range
     Msgbox "Select a cell within the appropriate range please"
End If
 
L

Legacy 1363

Guest
I think that the OP wants to check the value of the active cell with the values in A6:A47.

But she/he does not explain what sort of check is required - i.e. whether to check that the value exists in the range, or whether the value is within (or perhaps not outside of) the range of values within the range, or something else
 

Watch MrExcel Video

Forum statistics

Threads
1,122,819
Messages
5,598,293
Members
414,223
Latest member
Accountant2B

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top