+ Reply to Thread
Results 1 to 8 of 8

looping through headers and pasting information

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    51

    looping through headers and pasting information

    Hey all,

    I have 2 headers which need to be filled in to the end of the worksheet. I have the first two rows filled out with the proper information, I just can't figure out how to move over 2 cells paste the information and continue this until the end of the file. any help is greatly appreciated!
    Last edited by omgeokid; 01-31-2011 at 03:08 PM. Reason: solved

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,304

    Re: looping through headers and pasting information

    Post your code ... ideally in a sample workbook.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-10-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: looping through headers and pasting information

    I figured I would get that, but I really don't know what I can and can't post due to confidentiality in my office, I'm pretty sure I can post what I have, I'd rather just not post the whole workbook/sample workbooks.

    ThisWorkbook.Activate
                    Worksheets(dc).Activate
                    'need to make these cells dynamic, not specific
                    Cells(1, 2) = svr & "," & dname & "'I/Os per Second'"
                    Cells(1, 3) = svr & "," & dname & "'Response Time (ms)'"
    svr is dependent upon user input, and dname is handled in a loop prior to this block. I need those two headers pasted through the entire workbook in the first cell.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,304

    Re: looping through headers and pasting information

    You don't need to post the confidential data ... just what you want to end up with (in terms of the headings).

    What does this mean: "I need those two headers pasted through the entire workbook in the first cell."?

    Cells(1, 2) and Cells(1, 3) are cells B1 and C1 so how is that the "first cell".

    What do you mean by "through the entire workbook"? Each sheet in the workbook? Are there any sheets that don't want this writing to them?

    Regards

  5. #5
    Registered User
    Join Date
    01-10-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: looping through headers and pasting information

    sorry, still new to terms and whatnot.

    Cells(1, 2) = svr & "," & dname & "'I/Os per Second'"
    Cells(1, 3) = svr & "," & dname & "'Response Time (ms)'"
    These two cells are headers, they are in cell b1 and c1, but I need them replicated through the *worksheet*, not workbook sorry, in the first *row* not first cell.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,304

    Re: looping through headers and pasting information

    I'm still not sure I understand what you are trying to do but the following code will repeat those two cells across the top row.

    It looks longer than it really is due to a) having to define and set up some test variables, and b) the comments which will, hopefully, clarify what's going on.

    General caveat: this is one way to do it; there may be other and better ways.

    Regards

    Option Explicit
    Sub Test()
    Dim svr As String   ' for testing
    Dim dname As String ' for testing
    Dim LastCol As Long ' last colum
    Dim i As Long       ' loop counter
    Dim tRange As Range ' Target Range for copying to
    '
    svr = "s"               ' for testing
    dname = "d"             ' for testing
    LastCol = Columns.Count ' identify last column
    ' original cell formulae
    Cells(1, 2) = svr & "," & dname & "'I/Os per Second'"
    Cells(1, 3) = svr & "," & dname & "'Response Time (ms)'"
    ' Build Target Range
    For i = 4 To LastCol - 2 Step 2
        If tRange Is Nothing Then
            Set tRange = Cells(1, i)
        Else
            Set tRange = Union(tRange, Cells(1, i))
        End If
    Next 'i
    ' copy "base" cells across the top row
    Range("B1:C1").Copy tRange
    End Sub

  7. #7
    Registered User
    Join Date
    01-10-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: looping through headers and pasting information

    That was exactly what I was trying to do, thank you very much TM, that worked perfectly. Sorry about the confusion in describing what I needed to do.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,304

    Re: looping through headers and pasting information

    You're welcome. Thanks for the feedback.

+ 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