+ Reply to Thread
Results 1 to 2 of 2

Help to create workbook that arranges columns

Hybrid View

  1. #1
    Registered User
    Join Date
    01-09-2006
    Posts
    26

    Question Help to create workbook that arranges columns

    I have a repetative task that I beleive could automated....

    I will simplify the scenario (basically the same, but the actual sheet has more like 40 columns rather than the 4 I will use for example)...

    I have a sheet with 4 columns with headers:
    A1=Name B1=Address C1=Phone D1=City

    I need to rearranage the columns to the proper order to import to an online system like this:
    A1=Address B1=Name C1=City D1=Phone

    The headers on the original sheet are always the same, but dont always come in the same order.

    And the desired final column-order output is always the same.

    Can I create a workbook with two sheets...the first to paste new data into in it's original order, and the other that references the first sheet (headers) and displays the columns in the appropriate order?

    Any suggestions would be much appreciated!
    Thanks!

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    See if this gets you going.

    Sub aaa()
      Dim OutSH As Worksheet, DataSH As Worksheet
      Set OutSH = Sheets("sheet2")
      Set DataSH = Sheets("sheet1")
      lastrow = DataSH.Cells(Rows.Count, 1).End(xlUp).Row
      For Each ce In OutSH.Range("a1:" & OutSH.Cells(1, Columns.Count).End(xlToLeft).Address)
        getcol = WorksheetFunction.Match(ce.Value, DataSH.Rows("1:1"), 0)
        DataSH.Range(datash.Cells(2, getcol), datash.Cells(lastrow, getcol)).Copy Destination:=ce.Offset(1, 0)
      Next ce
      
    End Sub

    rylo
    Last edited by rylo; 02-15-2007 at 08:04 PM.

+ 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