Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add a new row to the "database" (macro), just copy copy formulas and formats (excel 2003)

Posted on 2011-03-08
9
Medium Priority
?
279 Views
Last Modified: 2012-05-11
Using the left most cell of the header (in bold), perhaps creating assigning a name to it.  So the the length of the first row below can be identified, then:
-Copy the first row below the header (this 2007 verbiage, my apologies, but we doing this in 2003)
-Paste (only formats and formulas) and move down the current cell contents down one row.

This simplifies the adding of new data to the "table".  Please include excel workbook with the solution.

See attached.
Thanks,
Juan sss Macro--Add-rows---same-format-an.xls
0
Comment
Question by:easycapital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 35075725
JP, Something like this, with the name StartData added to cell C7?

Sub asdgfasg()

With Range("startData")

    .Offset(1).EntireRow.Insert
    .Offset(2).EntireRow.Copy .Offset(1).EntireRow
    .Offset(1).EntireRow.SpecialCells(xlCellTypeConstants).ClearContents

End With

End Sub

Open in new window


Thomas
0
 
LVL 39

Accepted Solution

by:
nutsch earned 2000 total points
ID: 35075730
Here is is in a file

Thomas
Macro--Add-rows---same-format-an.xls
0
 

Author Closing Comment

by:easycapital
ID: 35075792
Thomas,
Real nice.  It looks good.  Just tried it, I guess time is the best test.
Will post again if I encounter problems.
Thanks!
JP
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 39

Expert Comment

by:nutsch
ID: 35075801
Glad to help again, thanks for the grade.

Thomas
0
 
LVL 81

Expert Comment

by:byundt
ID: 35075827
If the first row contains all formulas, you will get a fatal error with Thomas' macro. Here is the patch:
Sub NewRecord()
Dim rg As Range
Application.ScreenUpdating = False
With Range("HeaderRow")
    .Offset(1).EntireRow.Insert
    .Offset(2).Copy .Offset(1)
    On Error Resume Next
    Set rg = .Offset(1).SpecialCells(xlCellTypeConstants)
    On Error GoTo 0
    If Not rg Is Nothing Then rg.ClearContents
End With
Application.ScreenUpdating = True
End Sub

Open in new window


Brad
Macro--Add-rows---same-formatQ26.xls
0
 
LVL 39

Expert Comment

by:nutsch
ID: 35075838
touché

T
0
 

Author Comment

by:easycapital
ID: 35075932
Brad,

Great, and thanks for sharing that one!  I am wondering why does the new row inherit the height of the header row and not of the row below the header. Ie. try increasing the height of the header row and then apply macro.

JP
0
 
LVL 39

Expert Comment

by:nutsch
ID: 35075997
inserting a row gets the default format from the row above, that's why. So an update to avoid the row height issue could be:

Sub asdgfasg()

With Range("startData")

    .Offset(2).EntireRow.Insert
    .Offset(1).EntireRow.Copy .Offset(2).EntireRow
    On Error Resume Next
    .Offset(1).EntireRow.SpecialCells(xlCellTypeConstants).ClearContents
    On Error GoTo 0
End With

End Sub

Open in new window




0
 

Author Comment

by:easycapital
ID: 35076034
Brad and Thomas,

Resolved, thank you very much.  

Real time saver.

JP

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question