Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Add the following line immediately above the "With
rngNewRow.SpecialCells(Type:=xlCellTypeConstants)" line to prevent an error, if the current row has no data in it: On Error Resume Next -- Regards, Bill "Bill Renaud" wrote in message ... I re-wrote the routine as shown below, since the merged cell would get complicated otherwise. Also, I did not include code to add the diagonal drawing line the the Mileage cells in columns $K:$L, as I think this would get VERY complex. Could you just leave columns $K and $L as normal (i.e. label column $K "Mileage" and column $L "Mileage Cost")? Also as another suggestion, I would insert a blank row immediately above your Totals at the bottom and include that row in your formulas, but then hide that row. This will prevent problems if the user is already on the last data entry row (row 137?) and then they insert a new row. If this happened, then you would have to include code in your macro to revise the formulas for the Totals. There might still be a small chance that the last row would not get summed up in the Totals if the user defeats your template somehow. 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 '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, Bill "iltf124 no spam @hotmail.com" wrote in message om... My only task left is to test whether or not I can get the formatting of the cells to copy over along with the formulas. As you can tell by looking at my image....http://php.indiana.edu/~cawagner/templatescreen2.jpg the formulas copied over nicely...but I am wondering if there is anything I can modify/add that will copy over the the merged cell as a merged cell (instead of 3 separate ones). I am specifically talking about columns B-D. Originally, I had B12 as a merged cell that merged across columns B-D, but when I insert the row....it reverts back to 3 separate cells (similar to screen shot = b12, c12, d12 instead of just B12). Additionally, I have a drawing line going diagonal from K11:J11, is there any code that will keep that intact when I insert the row? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
macro for inserting one row between different data | Excel Discussion (Misc queries) | |||
Macro Inserting a formula | Excel Discussion (Misc queries) | |||
inserting row macro | Excel Discussion (Misc queries) | |||
Inserting Rows Through a Macro | Excel Programming | |||
INSERTING ROWS WITH A MACRO | Excel Programming |