Add a new row to the "database" (macro), just copy copy formulas and formats (excel 2003)
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.
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).ClearContentsEnd WithEnd Sub
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 RangeApplication.ScreenUpdating = FalseWith 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.ClearContentsEnd WithApplication.ScreenUpdating = TrueEnd Sub
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.
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 0End WithEnd Sub
Open in new window
Thomas