I would like to write to a text file from Excel, but the data order is different from the column order in Excel. For Example:

Excel Column : Col1,   Col2,   Col3,   Col4,   Col5    
Text file    : Col1,   Col2,   Col5,   Col4,   Col3

Please help me to solve this problem.


Simple: make a copy of the current sheet and change the column order within the copy before saving. When you don't need the copy then any more, delete it.

  • Comment from @adsy2010: You could even make a macro to resort the second sheet # (adsy2010, you now have enough rep to comment, please re-submit it as one and I will delete this placeholder).
    – Synetech
    Nov 28 '13 at 4:03

Thank you for answer.
I developed the following way of doing it:


For i = 1 To LastRow

    For j = 2 To 10
            Select Case j
            Case 3
                 strCellValue = Trim(shSheetName.Cells(i, j + 2).Value)
            Case 5
                 strCellValue = Trim(shSheetName.Cells(i, j - 2).Value)
            Case Else
                 strCellValue = Trim(shSheetName.Cells(i, j).Value)
            End Select
    Next j
        'Process of Write [strCellValue] to text file
Next i

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.