Results 1 to 3 of 3

Reverse columns using VBA

Threaded View

  1. #1
    Registered User
    Join Date
    08-05-2013
    Location
    Romania
    MS-Off Ver
    Excel 2010
    Posts
    7

    Reverse columns using VBA

    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!
    Last edited by AliGW; 07-23-2018 at 03:52 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to revers this Macro to Pull Data from closed workbook with ADO.Connection
    By nordicdust in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-19-2018, 04:06 PM
  2. Replies: 5
    Last Post: 10-06-2017, 03:59 PM
  3. Replies: 4
    Last Post: 08-20-2017, 06:40 PM
  4. Macro to Copy from 2 Columns, Paste Value in the next 2 Columns, Then clear 1st Columns
    By MHALTTUNEN in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-22-2014, 03:34 PM
  5. Combining multiple rows from 2 columns into sorted columns depending on 1st columns value
    By Dexamphetamine in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-11-2013, 10:00 AM
  6. Replies: 6
    Last Post: 04-11-2013, 11:27 AM
  7. [SOLVED] Looking for function or formula to calculate number that is revers
    By Ken in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-07-2005, 08:06 AM

Tags for this Thread

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