+ Reply to Thread
Results 1 to 4 of 4

How to repeat macro until end

Hybrid View

  1. #1
    Registered User
    Join Date
    02-27-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    4

    How to repeat macro until end

    I have a macro which uses the first row of data and copy and pastes it to a new sheet in a certain order. How do I get that process to continue for every row until the end of the data?
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to repeat macro until end

    Hi aeop

    The Code you reference is not in the Workbook you attached. It's a bit difficult to help amend Code we can't see.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: How to repeat macro until end

    Something like this

    Option Explicit
    
    Sub abc()
     Const shStart As String = "start"
     Const shFinish As String = "finish"
     Dim aArr, b, i As Long, ii As Long, n As Long
     
     
     With Worksheets(shStart)
        aArr = .Range("a1").CurrentRegion.Value
     End With
     
     ReDim b(1 To UBound(aArr) * 8, 1 To 5)
     
     For i = 2 To UBound(aArr)
        n = n + 1
        b(n, 1) = aArr(1, 1)
        b(n, 2) = aArr(1, 2)
        b(n, 3) = aArr(1, 4)
        b(n, 4) = "Phase"
        b(n, 5) = "Amount"
        n = n + 1
        b(n, 1) = aArr(i, 1)
        b(n, 2) = aArr(i, 2)
        b(n, 3) = aArr(i, 4)
        b(n, 4) = aArr(1, 5)
        b(n, 5) = aArr(i, 5)
        n = n + 1
        b(n, 1) = aArr(i, 1)
        b(n, 2) = aArr(i, 2)
        b(n, 3) = aArr(i, 4)
        b(n, 4) = aArr(1, 7)
        b(n, 5) = aArr(i, 7)
        
        For ii = 9 To UBound(aArr, 2)
            n = n + 1
            b(n, 1) = aArr(i, 1)
            b(n, 2) = aArr(i, 2)
            b(n, 3) = aArr(i, 4)
            b(n, 4) = aArr(1, ii)
            b(n, 5) = aArr(i, ii)
        Next
        n = n + 2
     Next
     With Worksheets(shFinish)
        .Cells.Clear
        .Range("a1").Resize(n, 5) = b
        .Columns.AutoFit
     End With
    End Sub
    Last edited by mike7952; 03-04-2013 at 01:02 PM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: How to repeat macro until end

    Maybe:

    Sub aeop()
    Dim lr As Long
    Dim y As Integer
    Dim x As Integer
    Dim ws As Worksheet
    Dim rcell As Range
    
    Application.ScreenUpdating = False
    
    Set ws = ActiveSheet
    
    lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
    
    For Each rcell In ws.Range("A2:A" & lr)
    
        x = 6
        y = 1
        
        ws.Range("A1").Copy Sheets("Finish").Range("A" & Rows.Count).End(3)(4)
        ws.Range("B1").Copy Sheets("Finish").Range("B" & Rows.Count).End(3)(4)
        ws.Range("D1").Copy Sheets("Finish").Range("C" & Rows.Count).End(3)(4)
        Sheets("Finish").Range("D" & Rows.Count).End(3)(4).Value = "Phase"
        Sheets("Finish").Range("E" & Rows.Count).End(3)(4).Value = "Amount"
        
        Do Until x = 0
        
            ws.Range(rcell, rcell.Offset(, 2)).Copy Sheets("Finish").Range("A" & Rows.Count).End(3)(2)
            Sheets("Finish").Range("D" & Rows.Count).End(3)(2) = "Phase" & y
            Sheets("Finish").Range("C" & Rows.Count).End(3)(2) = "New"
                Select Case y
                
                    Case Is = 1
                
                        Sheets("Finish").Range("E" & Rows.Count).End(3)(2) = rcell.Offset(, 4).Value
            
                    Case Is = 2
                    
                        Sheets("Finish").Range("E" & Rows.Count).End(3)(2) = rcell.Offset(, 6).Value
                    
                    Case Is = 3
                    
                         Sheets("Finish").Range("E" & Rows.Count).End(3)(2) = rcell.Offset(, 8).Value
    
                    Case Is = 4
                    
                        Sheets("Finish").Range("E" & Rows.Count).End(3)(2) = rcell.Offset(, 9).Value
    
                    Case Is = 5
                    
                        Sheets("Finish").Range("E" & Rows.Count).End(3)(2) = rcell.Offset(, 10).Value
                    
                    Case Is = 6
                    
                        Sheets("Finish").Range("E" & Rows.Count).End(3)(2) = rcell.Offset(, 11).Value
    
            End Select
    
            x = x - 1
            y = y + 1
        Loop
        
    
    Next rcell
    
    Sheets("Finish").Range("A1:A3").EntireRow.Delete xlUp
    
    Application.ScreenUpdating = True
    
    
    End Sub

+ 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