+ Reply to Thread
Results 1 to 2 of 2

Macro copies rows based on condition, BUT rows copy in Wrong order. PLEASE HELP!

  1. #1
    Registered User
    Join Date
    11-15-2014
    Location
    United States
    MS-Off Ver
    Excel 365
    Posts
    6

    Macro copies rows based on condition, BUT rows copy in Wrong order. PLEASE HELP!

    Here is my Macro:

    Sub Macro2()
    Dim lr As Long, lr2 As Long, lr3 As Long, lr4 As Long, r As Long
    lr = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
    lr2 = Sheets("R.Stallings").Cells(Rows.Count, "A").End(xlUp).Row
    lr3 = Sheets("J.Allard").Cells(Rows.Count, "A").End(xlUp).Row
    lr4 = Sheets("A.Godoy").Cells(Rows.Count, "A").End(xlUp).Row
    For r = lr To 2 Step -1
    Select Case Range("B" & r).Value
    Case Is = "R.Stallings"
    Range(Cells(r, 1), Cells(r, 8)).Copy Destination:=Sheets("R.Stallings").Range("A" & lr2 + 1)
    lr2 = Sheets("R.Stallings").Cells(Rows.Count, "A").End(xlUp).Row
    Case Is = "J.Allard"
    Range(Cells(r, 1), Cells(r, 8)).Copy Destination:=Sheets("J.Allard").Range("A" & lr3 + 1)
    lr3 = Sheets("J.Allard").Cells(Rows.Count, "A").End(xlUp).Row
    Case Is = "A.Godoy"
    Range(Cells(r, 1), Cells(r, 8)).Copy Destination:=Sheets("A.Godoy").Range("A" & lr4 + 1)
    lr4 = Sheets("A.Godoy").Cells(Rows.Count, "A").End(xlUp).Row
    End Select
    Next r
    End Sub




    The Problem that i am having is that when it copies the rows to the other sheets, the order in which it pastes them is reversed. For example if rows 1-5 have "J.Allard" in Column B, the macro is pasting those rows in Sheet("J.Allard") in descending order (5-1). I DO NOT want this. I want the rows to paste in the same order that they appear.

    Any help is greatly appreciated. Im new to macros so im sorry if this is a simple question.

    Thank you

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,474

    Re: Macro copies rows based on condition, BUT rows copy in Wrong order. PLEASE HELP!

    ' your telling it to start at the bottom
    Please Login or Register  to view this content.

    'starts the loop from the top
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro/VBA to Change Order of Rows/Add Rows based on specific text content presence/absence
    By cmaunder in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2013, 04:50 PM
  2. macro to copy rows to another sheet based on condition mentioned in another workbook
    By sona_tejas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2013, 06:23 AM
  3. [SOLVED] Customize code for a macro that copies three rows to a new workbook based on a condition
    By philips in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 01-04-2013, 05:55 AM
  4. Macro to copy rows to another worksheet based on condition
    By wthomas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2012, 01:11 PM
  5. Excel Macro to insert two rows based on condition and copy and paste multiple cells
    By mannabhalo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-13-2012, 12:56 PM

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