Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
restricting access using a macro Popeye the powerman[_2_] Excel Worksheet Functions 3 March 21st 09 07:16 AM
Macro Execution C Brandt Excel Discussion (Misc queries) 2 July 13th 07 07:23 AM
Macro Execution, Part Duo C Brandt Excel Discussion (Misc queries) 1 July 12th 07 10:57 PM
Restricting Macro Execution Bob Umlas[_3_] Excel Programming 2 December 3rd 03 04:29 PM
automatic macro execution Jos reulen Excel Programming 4 November 10th 03 03:10 PM


All times are GMT +1. The time now is 12:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"