Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Help with restricting InsertCopiedRow - Macro help

Pasted below is the code that I used to for my InsertCopiedRow macro
once a command button is selected within my excel template.

What am I trying to change???? I want to create some sort of IF that
only lets my InsertCopideRow function be executed if the ActiveCell is
in the range of G1:M20. If the user is trying to execute the macro and
is outside of the range, I will simply use a MsgBox as the error
handler.I have been trying many different IF statements within this
function, but I cant seem to find my way on this one. Thanks in advance
for your help.

Code
---------------
Sub InsertCopiedRow()
Dim ws As Worksheet
Dim rngCurrentRow As Range
Dim rngNewRow As Range

Application.ScreenUpdating = False
ActiveSheet.Unprotect "*****"

Set ws = ActiveSheet
Set rngCurrentRow = ActiveCell.EntireRow

'Step down a row and insert a new row.
rngCurrentRow.Offset(1, 0).Insert Shift:=xlDown

'Now define the new row to be the newly inserted row.
Set rngNewRow = rngCurrentRow.Offset(1, 0)

'Copy the current row down to the new row.
'This will also copy the merged cells as is.
rngCurrentRow.Copy
ws.Paste Destination:=rngNewRow
Application.CutCopyMode = False

On Error Resume Next

'New select and clear any constants and comments.
'Formulas and formats will remain.
With rngNewRow.SpecialCells(Type:=xlCellTypeConstants)
.ClearContents
.ClearComments
End With

'Select column $A for user convenience.
rngNewRow.Cells(1, 1).Select
ActiveSheet.Protect "*****"
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with restricting InsertCopiedRow - Macro help

Sub InsertCopiedRow()
Dim ws As Worksheet
Dim rngCurrentRow As Range
Dim rngNewRow As Range

Application.ScreenUpdating = False
ActiveSheet.Unprotect "*****"
if Intersect(ActiveCell, Range("G1:M20")) is Nothing then
msgbox "Selection must be in the range G1:M20"
exit sub
end if
Set ws = ActiveSheet
Set rngCurrentRow = ActiveCell.EntireRow

'Step down a row and insert a new row.
rngCurrentRow.Offset(1, 0).Insert Shift:=xlDown

'Now define the new row to be the newly inserted row.
Set rngNewRow = rngCurrentRow.Offset(1, 0)

'Copy the current row down to the new row.
'This will also copy the merged cells as is.
rngCurrentRow.Copy
ws.Paste Destination:=rngNewRow
Application.CutCopyMode = False

On Error Resume Next

'New select and clear any constants and comments.
'Formulas and formats will remain.
With rngNewRow.SpecialCells(Type:=xlCellTypeConstants)
.ClearContents
.ClearComments
End With

'Select column $A for user convenience.
rngNewRow.Cells(1, 1).Select
ActiveSheet.Protect "*****"
Application.ScreenUpdating = True
End Sub

--
Regards,
Tom Ogilvy

"Clint Wagner" wrote in message
...
Pasted below is the code that I used to for my InsertCopiedRow macro
once a command button is selected within my excel template.

What am I trying to change???? I want to create some sort of IF that
only lets my InsertCopideRow function be executed if the ActiveCell is
in the range of G1:M20. If the user is trying to execute the macro and
is outside of the range, I will simply use a MsgBox as the error
handler.I have been trying many different IF statements within this
function, but I cant seem to find my way on this one. Thanks in advance
for your help.

Code
---------------
Sub InsertCopiedRow()
Dim ws As Worksheet
Dim rngCurrentRow As Range
Dim rngNewRow As Range

Application.ScreenUpdating = False
ActiveSheet.Unprotect "*****"

Set ws = ActiveSheet
Set rngCurrentRow = ActiveCell.EntireRow

'Step down a row and insert a new row.
rngCurrentRow.Offset(1, 0).Insert Shift:=xlDown

'Now define the new row to be the newly inserted row.
Set rngNewRow = rngCurrentRow.Offset(1, 0)

'Copy the current row down to the new row.
'This will also copy the merged cells as is.
rngCurrentRow.Copy
ws.Paste Destination:=rngNewRow
Application.CutCopyMode = False

On Error Resume Next

'New select and clear any constants and comments.
'Formulas and formats will remain.
With rngNewRow.SpecialCells(Type:=xlCellTypeConstants)
.ClearContents
.ClearComments
End With

'Select column $A for user convenience.
rngNewRow.Cells(1, 1).Select
ActiveSheet.Protect "*****"
Application.ScreenUpdating = True
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
restricting use of certain characters Rob Excel Discussion (Misc queries) 4 June 8th 06 01:07 AM
restricting fonts Ernesto Herrera Jr. Excel Programming 1 February 24th 04 07:05 AM
Restricting Macro Execution Bob Umlas[_3_] Excel Programming 2 December 3rd 03 04:29 PM
Restricting Macro Execution John Wilson Excel Programming 1 December 3rd 03 03:43 PM


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