Results 1 to 6 of 6

Thread: Swapping Multiple Columns of Data

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    Rep Power
    0

    Swapping Multiple Columns of Data

    Rick,

    I'm using your SWAP Columns macro , and am having an issue. See the attachment with before and after sheets. I've posted the macro below, configured the way I'm using it. The problem is that Column Z, "Contract Manager Region" in the "Before" tab, is being deleted in the "After" tab, and Column AE, "Subject" in the "Before" tab, is being correctly moved to Column E in the "After" tab, but is also staying in AE in the "After" tab, where "Contract Manager Region" should be. Do I have something configured wrong?
    Code:
    Sub RearrangeColumns()
    'http://www.excelfox.com/forum/f22/swapping-rearranging-multiple-columns-data-493/
    'in the code as expressed below, column C moves to first position, B stays in second, E is thrd, etc.
    'Const NewOrder As String = "C,B,E,F,H,AC,K,AF,T,M,S,G,X,I,Z,AA,L,AG,AE,AH,AD,AI,A,D,J,N,O,P,Q,R,U,V,W,Y,AB,AJ"
      
      Dim X As Long, LastRow As Long, Letters As Variant
      'Type in order of what column you want in what position
      'Make sure there are no spaces in this string
      Const NewOrder As String = "D,E,AC,AD,AE,AB,B,C,F,G,H,I,J,K,L,M,N,P,X,Y,Q,R,S,T,U,V,W,A,AA,O,Z"
      LastRow = Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
      Letters = Split(NewOrder, ",")
      For X = 0 To UBound(Letters)
        Letters(X) = Columns(Letters(X)).Column
      Next
      Range("A1").Resize(LastRow, UBound(Letters)) = Application.Index(Cells, Evaluate("ROW(1:" & LastRow & ")"), Letters)
    End Sub
    Attached Files Attached Files
    Last edited by jomili; 09-28-2012 at 05:40 PM. Reason: added ref

Similar Threads

  1. Swapping (Rearranging) Multiple Columns of Data
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 13
    Last Post: 07-15-2014, 05:21 AM
  2. Replies: 2
    Last Post: 03-05-2013, 07:34 AM
  3. Converge Data From Multiple Columns To Single Column
    By ayazgreat in forum Excel Help
    Replies: 3
    Last Post: 12-14-2012, 10:55 PM
  4. Swapping columns Error 2
    By jomili in forum Excel Help
    Replies: 1
    Last Post: 11-16-2012, 08:52 PM
  5. Replies: 2
    Last Post: 06-14-2012, 04:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •