+ Reply to Thread
Results 1 to 3 of 3

Copy rows and count

Hybrid View

  1. #1
    Registered User
    Join Date
    05-29-2006
    Posts
    2

    Copy rows and count

    Hi,

    New to this forum and new to Excel VBA ;-)
    This is my problem:
    I have a worksheet with five columns, the first has values ending with numbers "01". I want to copy the rows, one by one, to another worksheet, 20 times, with the first column incrementing from "01" to "20". Then the next row with the same incrementing and so on, until the end of the range.

    Regards,
    Ralph Utbult

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    Try something like

    Sub Test()
    Set DataRange = Range(Cells(1, 1), Cells(100, 1))
    For Each Cell In DataRange
    For N = 1 To 20
    Sheets("Sheet2").Cells(65536, 1).End(xlUp).Offset(1, 0) = Left(Cell, Len(Cell) - 2) & Left("00", 2 - Len(N)) & N
    Range(Cells(Cell.Row, 2), Cells(Cell.Row, Cells(Cell.Row, 256).End(xlToLeft).Column)).Copy Destination:=Sheets("Sheet2").Cells(65536, 1).End(xlUp).Offset(0, 1)
    Next N
    Next Cell
    End Sub

    This will create a list on the second sheet with the 20 values stacked beneath each other. I assume that this is what you wanted.
    Martin

  3. #3
    Registered User
    Join Date
    05-29-2006
    Posts
    2
    Quote Originally Posted by mrice
    Try something like


    Range(Cells(Cell.Row, 2), Cells(Cell.Row, Cells(Cell.Row, 256).End(xlToLeft).Column)).Copy Destination:=Sheets("Sheet2").Cells(65536, 1).End(xlUp).Offset(0, 1)

    This will create a list on the second sheet with the 20 values stacked beneath each other. I assume that this is what you wanted.
    Thanks!
    It worked great, with a small amount of customization, of course ;-)
    I narrowed the area that gets copied:
    Range(Cells(Cell.Row, 14), Cells(Cell.Row, 18)).Copy destination:=Sheets("Sheet2").Cells(65536, 1).End(xlUp).Offset(0, 1)

    My code has cut time from two hours to 5 minutes and gotten rid of the mistakes involved in tedious, repititive work. I'm really happy about this!

    Regards,
    Ralph

+ 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