View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Umlas[_3_] Bob Umlas[_3_] is offline
external usenet poster
 
Posts: 320
Default Restricting Macro Execution

If Activecell.Address<"$A$1" then
Msgbox "yada yada"
Exit Sub
End If
'rest of macro here

Bob Umlas
Excel MVP
"Terry" wrote in message
...
I have used use Excel to create macro. I am trying to
modify macro to execute only when I put cursor in first
cell (A1). Otherwise, I want the macro to print out
statement in Message Box "Put Cursor in Correct Cell".
Any ideas? Thanks.
Terry

Sub SortRows()
'
' SortRow2 Macro
' Keyboard Shortcut: Ctrl+t


If ActiveCell.Range("A1") Then
ActiveCell.Range("A1:I19").Select
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveCell.Range("A1:I19").Select
Selection.Interior.ColorIndex = xlNone
ActiveCell.Range( _
"A1:I1,A3:I3,A5:I5,A7:I7,A9:I9,A11:I11,A13:I13 ,A15
:I15,A17:I17,A19:I19").Select
ActiveCell.Offset(18, 0).Range("A1").Activate
With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
Else
MsgBox "Put Cursor in Correct Cell"
End If
End Sub