+ Reply to Thread
Results 1 to 3 of 3

Re arrange columns from selected rows

Hybrid View

  1. #1
    Registered User
    Join Date
    02-17-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re arrange columns from selected rows

    All,
    I am attaching an excel file. It also contains the macro needed for "Click Here" button
    Sub Possible_Answer()
        Dim i As Long
        Dim copyRows As Range
    
        With Sheets("Sample Problem")
    
            For i = 7 To 13
                If .Range("C" & i).Value = "Jane Fake" Then
                    If copyRows Is Nothing Then
                        Set copyRows = .Rows(i)
                    Else
                        Set copyRows = Union(copyRows, .Rows(i))
                    End If
                End If
            Next
    
            If Not copyRows Is Nothing Then
                copyRows.Copy Sheets("Sample Problem").Rows(18)
            End If
        End With
    End Sub
    But I need to re-arrange few columns to fit the target table.

    Any help would be appreciated

    Thanks in advance
    Steve
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    02-17-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Re arrange columns from selected rows

    Found solution on another thread
    Sub Possible_Answer() 
        Dim ary As Variant 
        Dim sRows As String 
        Dim nextrow As Long 
        Dim i As Long 
         
        With Sheets("Sample Problem") 
             
            ary = Application.Transpose(.Evaluate("IF(C6:C12=""Jane Fake"",ROW(C6:C12))")) 
            sRows = Replace(Replace(Join(ary, ","), "False,", ""), "False", "") 
            ary = Split(sRows, ",") 
             
            nextrow = 17 
            For i = LBound(ary) To UBound(ary) 
                 
                .Cells(ary(i), "B").Copy .Cells(nextrow, "D") 
                .Cells(ary(i), "C").Resize(, 2).Copy .Cells(nextrow, "B") 
                .Cells(ary(i), "E").Copy .Cells(nextrow, "F") 
                .Cells(ary(i), "F").Copy .Cells(nextrow, "E") 
                nextrow = nextrow + 1 
            Next i 
        End With 
    End Sub

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Re arrange columns from selected rows

    Its great you found the solution. I will mark your thread as solved.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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