LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Inserting a Row With Macro - Help

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
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
macro for inserting one row between different data eva cheng Excel Discussion (Misc queries) 2 April 2nd 10 02:51 AM
Macro Inserting a formula Kristi Excel Discussion (Misc queries) 0 May 13th 09 05:29 PM
inserting row macro daroc Excel Discussion (Misc queries) 2 March 7th 06 06:27 PM
Inserting Rows Through a Macro Mike[_56_] Excel Programming 3 October 8th 03 03:52 AM
INSERTING ROWS WITH A MACRO Jay Dean Excel Programming 15 September 16th 03 05:08 PM


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