-5

I have large table with columns of dates : 1 january, 2 january, 3 january ...
But now it's crucial not to scroll right cause of big data.

My idea is to invert columns:27 june, 26 june ... 1 january
And after that paste column with new date at the left.

Is any tool to invert columns in default MS Excel or in VBA ?

3
  • 1
    Copy it, paste special and transpose, sort by your column, then copy/transpose back. Commented Jun 28, 2014 at 12:09
  • Thank you! Not ideal way, but worked. I think VBA can do this, did you saw some VBA script library ? Commented Jun 28, 2014 at 12:28
  • possible duplicate of sorting across sheets in excel Commented Jul 2, 2014 at 17:51

1 Answer 1

1

You could use this script from previous accepted answer about sorting columns across sheets: Sort excel columns across sheets

First create a new sheet as first in workbook. Then add columns headers with dates in desired order: 27 june... 1 june

Replace number of columns and number of sheets in script

Save a backup before running this macro, no undo.

After rearrangement delete first sheet

Sub ColumnRearrangement()
  'Horaciux 2014-06-23
Dim nextLabel As String
Dim currentLabel As String

Dim TotalPages As Integer
Dim TotalColumns As Integer

TotalPages = 10
TotalColumns = 200

'Insert a blank column in each page
For p = 2 To TotalPages
    Sheets(p).Select
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("B1").Select
Next

For c = TotalColumns To 1 Step -1
    Sheets(1).Select

    'Debug.Print "-" & Cells(1, c).Text & "-" & Str(c)
    nextLabel = Cells(1, c).Text
    Sheets(2).Select
    For oldCulumn = 2 To TotalColumns + 1

        'Debug.Print Cells(1, oldCulumn).Text & "-" & Str(oldCulumn)
        currentLabel = Cells(1, oldCulumn).Text

        If currentLabel = nextLabel Then
            'Debug.Print currentLabel & "-" & Str(oldCulumn)
            Exit For
        End If
    Next

    For p = 2 To TotalPages
        Sheets(p).Select
        Columns(oldCulumn).Select
        Selection.Cut
        Columns("A:A").Select
        Selection.Insert Shift:=xlToRight
    Next
Next

For p = 2 To TotalPages
    Sheets(p).Select
    Range("A1").Select
Next

End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

@SergeySenkov Does it work for you? Could you formally accept this answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.