Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 90
Default need to modify a macro to prevent it from executing if in wrong area of the sheet

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

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


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



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 90
Default need to modify a macro to prevent it from executing if in wrong area of the sheet

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
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



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
Auto Rename Excel Sheets in Workbook Kulin Shah Excel Worksheet Functions 12 December 25th 06 03:27 PM
macro unouwanme Excel Discussion (Misc queries) 9 August 31st 06 09:38 PM
Sum up columns in different sheet with error check zeyneddine Excel Discussion (Misc queries) 13 July 10th 06 01:21 PM
HELP!! Unhide Sheet with Macro and focus on other sheet [email protected] Excel Discussion (Misc queries) 2 May 23rd 06 07:17 PM
Selecting Last Sheet Bonbon Excel Worksheet Functions 17 February 22nd 06 04:16 PM


All times are GMT +1. The time now is 04:11 AM.

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

About Us

"It's about Microsoft Excel"