ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check current location (https://www.excelbanter.com/excel-programming/393487-check-current-location.html)

Jeff

Check current location
 
Hi,

I'm trying to create a macro that will only run when the active cell is in
certain locations. If the active cell is not in the correct location I want
to display an error message.

Any ideas gratefully received.



NickHK

Check current location
 
Jeff,
Depends how you determine the correct location:

Const MAXROW As Long = 10
If ActiveCell.Row MAXROW Then
MsgBox "Must be on/before row " & MAXROW
End If

Const MAXCOL As Long = 10
If ActiveCell.Column MAXCOL Then
MsgBox "Must be on/before column " & MAXCOL
End If

Const OK_RANGE As String = "D3:M26"
If Intersect(ActiveCell, Range(OK_RANGE)) Is Nothing Then
MsgBox "Must be in the range " & OK_RANGE
End If

NickHK

"Jeff" wrote in message
...
Hi,

I'm trying to create a macro that will only run when the active cell is in
certain locations. If the active cell is not in the correct location I

want
to display an error message.

Any ideas gratefully received.





Bob Phillips

Check current location
 
If Intersect(Activecell, Range("H1:M10")) Is Nothing Then
MsgBox "Not in correct location"
End If

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Jeff" wrote in message
...
Hi,

I'm trying to create a macro that will only run when the active cell is in
certain locations. If the active cell is not in the correct location I
want
to display an error message.

Any ideas gratefully received.





Jeff

Check current location
 
Perfect,

Thanks very much

"Bob Phillips" wrote:

If Intersect(Activecell, Range("H1:M10")) Is Nothing Then
MsgBox "Not in correct location"
End If

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Jeff" wrote in message
...
Hi,

I'm trying to create a macro that will only run when the active cell is in
certain locations. If the active cell is not in the correct location I
want
to display an error message.

Any ideas gratefully received.







All times are GMT +1. The time now is 11:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com