View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default need to modify a macro to prevent it from executing if in wrong area of the sheet

Glad to help but your code needs an entire rewrite.


--
Don Guillett
SalesAid Software

"Tonso" wrote in message
oups.com...
On Feb 11, 1:58 pm, "Don Guillett" wrote:
if activecell.row<10 then exit sub

You should also remove all selections as they are rarely necessary or
desirable.
--
Don Guillett
SalesAid Software
"Tonso" wrote in message

ps.com...



i have an excel 2002 workbook with the following VBA...


Sub InsertActivity()


Dim r As Long
Dim Start As Long
Dim answer As Long


answer = MsgBox("Are you sure that you want to INSERT an activity
here?", vbYesNo)
If answer < vbYes Then Exit Sub
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="flow"
r = ActiveCell.Row
Start = Cells(r, "A").Select
ActiveCell.Range("A1:AU1").Select
Selection.Copy
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
Start = Cells(r, "A").Select
ActiveCell.Offset(0, 1).Range("A1:AU1").Select
Selection.ClearContents
Start = Cells(r, "D").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingCells:=True, Password:="flow"
Application.ScreenUpdating = True
End Sub


it is for a form, and the macro allows the user to insert a row in the
body of the form in case a row needs to be added. It works great,
except if the active row is in the header part of the form, and not
the body of the form, where you would normally insert a line. If you
absent-minded forget that the active cell is in the header, the result
is a 2nd header of several lines being inserted. Several lines are
inserted because there are some merged cells in the header. What I
would like is to be able to modify this macro so if the active cell is
anywhere in the header rows 1 -19, the macro will inform you that you
cannot insert a row there, then exit the macro. I have put in the
warning message box, but it has been overlooked before, including by
myself even!


Thank you for your help as always,


Tonso- Hide quoted text -


- Show quoted text -


Thanks ever so much! That works perfect!
Tonso