Calling all Macro and VBA experts- the answer is simple but what?
Posted by sdimaggio on December 08, 2001 7:48 PM
I am trying to solve a small problem for all you VBA experts. I have a macro that automatically copies a database in workbook1 to workbook2 automatically and then sorts it while working in workbook1. The problem is I want to paste only selected columns (lets say A, C and D). I think there are two ways to go, I can either paste each column individually so they endup in workbook2 col. A,B and C, or set up a criteria, which I think is better. I know the solution is simple and is in the top half of the script. Ive tried a couple of different options but Im new to the VBA world. The script below works but it copies the whole database.
Sub AutoSort()
Application.ScreenUpdating = False
returncell = ActiveCell.Address
Cells.Select
Selection.Copy
Windows("Book2.xls").Activate
Sheets(1).Select
Range("A1").Select
ActiveSheet.Paste
'
' Application.CutCopyMode = False
Selection.Sort _
Key1:=Range("A2"), _
Order1:=xlDescending, _
Key2:=Range("C2"), _
Order2:=xlDescending, _
Key3:=Range("D2"), _
Order3:=xlDescending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
Range("A1").Select
Sheets(1).Select
Windows("Book1.xls").Activate
Range(returncell).Select
Application.ScreenUpdating = True
End Sub