![]() |
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 |
Restricting Macro Execution
Bob,
Your suggestion worked great. What if I want to designate multiple cells, say $A$1 and $A$5. Terry -----Original Message----- 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 . |
Restricting Macro Execution
Terry,
Just turn his code around..... If Activecell.Address="$A$1" Or ActiveCell.Address="$A$5" Then ' do your macro Else MsgBox "yada yada" Exit Sub End If John Terry wrote: Bob, Your suggestion worked great. What if I want to designate multiple cells, say $A$1 and $A$5. Terry -----Original Message----- 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 . |
All times are GMT +1. The time now is 08:45 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com