+ Reply to Thread
Results 1 to 6 of 6

Thread: Creating a template row ...

  1. #1
    Registered User
    Join Date
    09-21-2009
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    19

    Creating a template row ...

    Every time I need add something to the sheet I need copy a row with all the formulas and formatting and change it contents, is there any way each new row has a pre defined template with formatting and formulas?
    Last edited by Henrique; 09-23-2009 at 10:45 AM.

  2. #2
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,151

    Re: Creating a template row ...

    Hi, in Excel 2003 you can define your data table as a List. Highlight the table, including the column labels and then click Data - List - Create List and then hit OK.

    Now you should see a blue border around the data table. When you click inside the table, there will be a new empty row added to the bottom of the list, where formatting and calculations are automatically applied as in the cells above.

  3. #3
    Registered User
    Join Date
    09-21-2009
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Creating a template row ...

    Hum, not exactly what I asked. Attached is a sample sheet.

    You can see every two row correspond to the item on the B column. b3,b5,b7 ... I would like to create a template where every time I want add a new item I dont need to copy the cells, paste and replace the content.

    Would be nice to have the template on the top of the sheet, every time I fill the blank spaces it adds the group of two new rows containing all the data and formula to the end of the sheet and the template space get empty again to enter new values ...
    Attached Images Attached Images

  4. #4
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,151

    Re: Creating a template row ...

    Starting from your screenshot:

    place the cursor in cell A23
    start the macro recorder
    set it to relative cell referencing
    copy the two rows above the active cell
    do your paste and tidy up thing
    stop the macro recorder

    Next time you want to insert a new set of rows, place the cursor in Column A in the next empty row and run the macro.

    Lots of fine tuning can be done here, but this should give you a starting point. You could create a button somewhere on the sheet that runs the macro, you could use code to find the last empty cell by itself ....

  5. #5
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,150

    Re: Creating a template row ...

    try this in the worksheet
    Private Sub Worksheet_Change(ByVal Target As Range)
      
        
        Dim TargetCell As Range, N As Long
        
        On Error GoTo FormulaFillFail
       
        If (Not IsNumeric(Target.Value)) Or IsEmpty(Target) Then
            
            Exit Sub
        End If
       
        For Each TargetCell In Intersect(ActiveSheet.UsedRange, Target.EntireRow)
           
    
            If TargetCell.Value = "" Then
               
                For N = 1 To TargetCell.Row - 1
                    
                    If TargetCell.Offset(-N, 0).HasFormula Then
                        
                        TargetCell.Offset(-N, 0).Copy Destination:=TargetCell.Offset(-N + 1, 0).Resize(N, 1)
                       
                        Exit For
                    End If
                Next N
            End If
         
        Next TargetCell
        
        
       
       Exit Sub
        
        
    FormulaFillFail:
    
    
    End Sub
    i think its an old "Jack in the UK" code
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  6. #6
    Registered User
    Join Date
    09-21-2009
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Creating a template row ...

    I did what teylyn said and worked fine, thanks.

    I have not tried what Pike said since Im very new to excel and VB, I couldnt figure what variables to change in the code to get it working.

    The range is Range("A1:X2")

    Thanks,

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0