Reorder headers and store into 1d array

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Reorder headers and store into 1d array

Post by YasserKhalil »

Hello everyone

I have the first row with some headers in about 12 columns and I need to search for specific headers from 1d array.

Code: Select all

    a = Array("Header3", "Header5", "Header10")
    For Each c In Range("A1").CurrentRegion.Rows(1).Cells
        x = Application.Match(c.Value, a, 0)
        If Not IsNumeric(x) Then
            ReDim Preserve s(n)
            s(n) = c.Column
            n = n + 1
        Else
            ReDim Preserve t(k)
            t(k) = c.Column
            k = k + 1
        End If
    Next c
The code works and reorders the headers into two new 1d arrays the array s() and the array t() then I am using this line to get a final 1d array with the new order I desire

Code: Select all

ar = Split(Join(s, ",") & "," & Join(t, ","), ",")
Is there a smarter approach to get the same result of the final 1d array??

The question posted here too
https://chandoo.org/forum/threads/reord ... ray.46965/