need to modify a macro to prevent it from executing if in wrong area of the sheet

T

Tonso

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
 
D

Don Guillett

if activecell.row<10 then exit sub

You should also remove all selections as they are rarely necessary or
desirable.
 
T

Tonso

if activecell.row<10 then exit sub

You should also remove all selections as they are rarely necessary or
desirable.
--
Don Guillett
SalesAid Software











- Show quoted text -

Thanks ever so much! That works perfect!
Tonso
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top