Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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



.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default 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



.


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
automatic macro execution Jos reulen Excel Programming 4 November 10th 03 03:10 PM
Hiding macro execution Angeliki Excel Programming 4 November 7th 03 01:35 PM
slow macro execution Vasile Dumitrescu Excel Programming 1 October 7th 03 03:31 PM


All times are GMT +1. The time now is 11:03 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"