Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Restricting Macro Execution
Terry,
Without going into a lot of detail deciphering your code, why not just Select A1 when the macro starts? That way, it'll always run from the correct cell. e.g. Instead of If ActiveCell.Range("A1") Then use Range("A1").Select You can then get rid of the Else, End If statements John Terry wrote: 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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Restricting Macro Execution
John,
If the macro is executed from other cell it could screw up the whole worksheet. What I have presented here is only a sample. Terry -----Original Message----- Terry, Without going into a lot of detail deciphering your code, why not just Select A1 when the macro starts? That way, it'll always run from the correct cell. e.g. Instead of If ActiveCell.Range("A1") Then use Range("A1").Select You can then get rid of the Else, End If statements John Terry wrote: 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 . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
restricting access using a macro | Excel Worksheet Functions | |||
Macro Execution | Excel Discussion (Misc queries) | |||
Macro Execution, Part Duo | Excel Discussion (Misc queries) | |||
Restricting Macro Execution | Excel Programming | |||
automatic macro execution | Excel Programming |