Check current location

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,
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
 
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)
 
Perfect,

Thanks very much

Bob Phillips said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top