+ Reply to Thread
Results 1 to 6 of 6

Repeating Column header for each row

  1. #1
    Registered User
    Join Date
    03-07-2006
    Posts
    16

    Repeating Column header for each row

    How to repeat column header for each row

    NAME JOB SALARY
    AAA CLERK 5000
    BBB MANAGER 6000
    CCC CASHIER 7000


    I want result as:

    NAME JOB SALARY
    AAA CLERK 5000
    NAME JOB SALARY
    BBB MANAGER 6000
    NAME JOB SALARY
    CCC CASHIER 7000

  2. #2
    Toppers
    Guest

    RE: Repeating Column header for each row

    Try:

    Sub a()
    Dim title() As String
    With Worksheets("Sheet1") '<=== change as needed
    lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
    titles = .Range("a1:c1")
    For r = lastrow To 3 Step -1
    .Cells(r, 1).EntireRow.Insert
    .Cells(r, 1).Resize(1, 3) = titles
    Next r
    End With
    End Sub

    "jamex" wrote:

    >
    > How to repeat column header for each row
    >
    > NAME JOB SALARY
    > AAA CLERK 5000
    > BBB MANAGER 6000
    > CCC CASHIER 7000
    >
    >
    > I want result as:
    >
    > NAME JOB SALARY
    > AAA CLERK 5000
    > NAME JOB SALARY
    > BBB MANAGER 6000
    > NAME JOB SALARY
    > CCC CASHIER 7000
    >
    >
    > --
    > jamex
    > ------------------------------------------------------------------------
    > jamex's Profile: http://www.excelforum.com/member.php...o&userid=32243
    > View this thread: http://www.excelforum.com/showthread...hreadid=537447
    >
    >


  3. #3
    Dave Peterson
    Guest

    Re: Repeating Column header for each row

    First, I think keeping the data in a nice tabular form is usually much better.

    There are lots of things that will become more difficult if you do this.

    But if you want, you can use a macro:

    Option Explicit
    Sub testme()

    Dim wks As Worksheet
    Dim iRow As Long
    Dim FirstRow As Long
    Dim LastRow As Long
    Dim HeaderRow As Long

    Set wks = Worksheets("sheet1")
    With wks
    HeaderRow = 1
    FirstRow = 2
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

    For iRow = LastRow To FirstRow + 1 Step -1
    .Rows(HeaderRow).Copy
    .Rows(iRow).Insert
    Next iRow
    End With
    Application.CutCopyMode = False
    End Sub

    If you're new to macros, you may want to read David McRitchie's intro at:
    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    jamex wrote:
    >
    > How to repeat column header for each row
    >
    > NAME JOB SALARY
    > AAA CLERK 5000
    > BBB MANAGER 6000
    > CCC CASHIER 7000
    >
    > I want result as:
    >
    > NAME JOB SALARY
    > AAA CLERK 5000
    > NAME JOB SALARY
    > BBB MANAGER 6000
    > NAME JOB SALARY
    > CCC CASHIER 7000
    >
    > --
    > jamex
    > ------------------------------------------------------------------------
    > jamex's Profile: http://www.excelforum.com/member.php...o&userid=32243
    > View this thread: http://www.excelforum.com/showthread...hreadid=537447


    --

    Dave Peterson

  4. #4
    Registered User
    Join Date
    03-07-2006
    Posts
    16
    Thanks topper, nice coding.

    Can we have other option to solve this problem other than you macro?

  5. #5
    Jim Cone
    Guest

    Re: Repeating Column header for each row

    First...
    In an adjacent column, consecutively number the rows and then repeat.
    Sort the data by the numbers to add a blank row between each row.

    NAME JOB SALARY
    1 AAA CLERK 5000
    2 BBB MANAGER 6000
    3 CCC CASHIER 7000
    4 DDD WIFE 8000
    5 EEE CHILD 9000
    1
    2
    3
    4
    5

    Second...
    Copy the titles.
    Third...
    Select the column with the names (not the entire column)
    Fourth...
    Edit | GoTo | Special | Blanks
    Fifth...
    Paste
    Sixth...
    Delete the extra column
    --
    Jim Cone
    San Francisco, USA
    http://www.realezsites.com/bus/primitivesoftware



    "jamex" wrote in message
    How to repeat column header for each row

    NAME JOB SALARY
    AAA CLERK 5000
    BBB MANAGER 6000
    CCC CASHIER 7000

    I want result as:

    NAME JOB SALARY
    AAA CLERK 5000
    NAME JOB SALARY
    BBB MANAGER 6000
    NAME JOB SALARY
    CCC CASHIER 7000
    --
    jamex


  6. #6
    vezerid
    Guest

    Re: Repeating Column header for each row

    jamex,

    you can do it with formulas. Assuming your data (first header, NAME)
    starts at A1, and assuming that your output starts at E1, you can use
    the following formula in E1:

    =IF(MOD(ROW()-ROW(E$1),2)=0,A$1,OFFSET(A$1,1+(ROW()-ROW(E$1))/2,0))

    This formula can be copied down and to the right, as far as necessary.
    Replace A1 and E1 to suit.

    HTH
    Kostis Vezerides


+ 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.6.0 RC 1