I'm using the following code to copy a particular range from a Workbook
to another Workbook
, its working fine.
But now i need to sort the Range
in ascending order just before pasting to the destination sheet without changing the source. Please help.
With Workbooks(strExcelFile).Sheets(strSheetName)
.Range(strRange).Copy
End With
ActiveSheet.Range(strDestCell).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
You should try to avoid the redundant
Select
when working with ranges. You can work more cleanly usingworksheets
andranges
as below, which is easily adaptable accross workbooks as per your questioncode
Take advantage of the fact that once you paste, your newly pasted range will be selected; then you can use SELECTION.
That test example will work in any excel file with some data in A1-A8. B1 in both places can be replaced with strDestCell and A1:A8 with strRange for your eventual subroutine.