Hello to everybody,
As told you at my first post, I'm still learning VBA :-)
Now I'm working on a sheet in which I import some data. Actually I will monthly import some figures, so in the end of the year I will have 12 columns.
In each month the txt file will contain the actual month and the month back until January.
The problem is that my txt file contains the month reversed. It starts all the time with the actual month and ends with January.
To use this sheet in my file I will need to reverse the order, so the first column will be January. Now I found this code:
Dim X As Long, LastRow As Long, Letters As Variant, NewLetters As Variant
Const NewOrder As String = "Z,Y,X,W,V,U,T,S,R,Q,P,O"
LastRow = Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
Letters = Split(NewOrder, ",")
ReDim NewLetters(1 To UBound(Letters) + 1)
For X = 0 To UBound(Letters)
NewLetters(X + 1) = Columns(Letters(X)).Column
Next
Range("O1").Resize(LastRow, UBound(Letters) + 1) = Application.Index(Cells, Evaluate("ROW(1:" & LastRow & ")"), NewLetters)
It does the job but only in case if I have a full year. If I import data for 5 month January it will be 6th column, and the first 6 are filled in with 0 values.
I would need your support to find a solution to this code so in any case January will be in the first row.
Thanks a lot!
Bookmarks