none
Moving columns based on conditions RRS feed

  • Question

  • Hi,

    I have a report with data ranges from column A to AZ(last column not always AZ and not fixed, it may be less than that, but not beyond AZ). what ever may be the no of columns, I need the the last two columns to be placed in column AL and AM. And delete the columns from AN onwards.

    Can there be VBA for this.

    Thanks

    Sunday, March 29, 2015 5:45 PM

All replies

  • For example:

    Sub MoveAndDelete()
        Dim c As Long
        c = Cells.Find(What:="*", SearchOrder:=xlByColumns, _
            SearchDirection:=xlPrevious).Column
        Range(Cells(1, c - 1), Cells(1, c)).EntireColumn.Copy
        Range("AL1").Insert
        Range(Cells(1, "AN"), Cells(1, Columns.Count)).EntireColumn.Delete
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Sunday, March 29, 2015 8:33 PM