Results 1 to 40 of 40

Sort multiple columns based on column header

Threaded View

  1. #1
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Sort multiple columns based on column header

    Hi All

    I need to format a sheet where the number of columns is not fixed. Sometimes the column name "Charged Date" is found in Column X or sometimes in Column Y etc. Basically I’d like to:
    • Find the column header “Charge Date”
    • Apply Autofilter to all columns
    • Sort from Oldest to Newest (Charge Date)

    I already use an array to id the the column headers and reorder the columns (see below) that I found on the forum.
     Dim arrColOrder As Variant, ndx As Integer
      Dim Find As Range, counter As Integer
        
        arrColOrder = Array("Library Location", "o:loi", "Barcode1", "Barcode2", "Invoice Number", "Price", _
                            "Charge Date", "Title", "Author", "Publisher", "Location Mark", "Catalogue record", "Sigillum", "Loan Object Class", "Genre")
        counter = 1
       
        For ndx = LBound(arrColOrder) To UBound(arrColOrder)
        
            Set Find = Rows("1:1").Find(arrColOrder(ndx), LookIn:=xlValues, LookAt:=xlWhole, _
                              SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
            
            If Not Find Is Nothing Then
                If Find.Column <> counter Then
                    Find.EntireColumn.Cut
                    Columns(counter).Insert Shift:=xlToRight
                    Application.CutCopyMode = False
                End If
                counter = counter + 1
            End If
            
        Next ndx
    There must be a way to use the same array to get the result I’m looking for or maybe there’s a faster way………

    Attached is a sample of the actual sheet.
    Attached Files Attached Files

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