Hi, I have a Macro that allows to select a file from an open workbook, copy the data from the selected workbook into the open workbook.
The copied / pasted data has multiple columns.
This macro is working well but I need the data pasted to be also sorted in descending order according to a specific column A (which has dates)
Please can you help me with what coding needs to be modified for the data pasted to be also sorted based on column A values dates? Thank you.
Sub OpenFile()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Select Workbook", FileFilter:="Excel Files (*.xlsx*), *xlsx*")
'& "Excel Files(*xlsx*), *xlsx*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets("Sheet1").UsedRange.Copy
ThisWorkbook.Worksheets("Sheet1").Range("A1").PasteSpecial xlPasteValues
OpenBook.Close False
Else
MsgBox "No file was selected!"
End If
Application.ScreenUpdating = True
End Sub
The copied / pasted data has multiple columns.
This macro is working well but I need the data pasted to be also sorted in descending order according to a specific column A (which has dates)
Please can you help me with what coding needs to be modified for the data pasted to be also sorted based on column A values dates? Thank you.
Sub OpenFile()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Select Workbook", FileFilter:="Excel Files (*.xlsx*), *xlsx*")
'& "Excel Files(*xlsx*), *xlsx*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets("Sheet1").UsedRange.Copy
ThisWorkbook.Worksheets("Sheet1").Range("A1").PasteSpecial xlPasteValues
OpenBook.Close False
Else
MsgBox "No file was selected!"
End If
Application.ScreenUpdating = True
End Sub