• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to sort worksheets based on the range

ThrottleWorks

Excel Ninja
Hi,

I have one excel file with multiple worksheets. For example, file name is 'Auto' and number of worksheets are 5. This number can be 5, 15 or 50.

Original name and order of the worksheets is as below.

Yamaha
Audi
BMW
KTM
Porsche

I have another excel file, in 'Sheet1' range ("A1:A5"), I have values as below.
Porsche
Audi
KTM
Yamaha
BMW

How do I arrange worksheets in file 'Auto' as per 'Sheet1' range ("A1:A5").
Can anyone please help me in this.

Apologies for not uploading sample file.
 

Sorry, I've a bit misread your initial post !
The reason why it's far better with an attachment.

So the easy way is a loop on range to reorder worksheets …
 
As it depends where the procedure is located but something like​
Code:
Sub Demo1()
        Dim V, R%
            V = Range("Sheet1!A1:A4").Value
    With Workbooks("Auto").Worksheets
        For R = 1 To 4
          .Item(V(R)).Move .Item(R)
        Next
    End With
End Sub
 
Back
Top