VBA - Check is activecell is within a range

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,291
Office Version
  1. 365
Platform
  1. Windows
I want to make sure at the start of a macro that the active cell in within

A6:A1000

if Activecell (is in range) then.....


Please help.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try

Code:
If Not Intersect(ActiveCell, Range("A6:A1000")) Is Nothing Then
    'code
End If
 
Upvote 0
As a matter of interest, why do you need to do this?
 
Upvote 0
I am a newbie, therefore my code will be like this... conservative but working. (For learning purposes only, please follow the code of the Excel MVPs).

Sub ActiveRC()

If ActiveCell.Column() <> 1 Or ActiveCell.Row() < 6 Or ActiveCell.Row() > 1000 Then
MsgBox "WRONG CELL SELECTED.", vbOKOnly + vbInformation, "Hello!!!"
Else
MsgBox "YOU ARE INSIDE THE RANGE.", vbOKOnly + vbInformation, "Yahoo!!!"
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,222,675
Messages
6,167,534
Members
452,118
Latest member
djjamesp

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
Back
Top