Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
restricting access using a macro | Excel Worksheet Functions | |||
restricting use of certain characters | Excel Discussion (Misc queries) | |||
restricting fonts | Excel Programming | |||
Restricting Macro Execution | Excel Programming | |||
Restricting Macro Execution | Excel Programming |