这个宏工作正常,但我知道它效率不高,必须有更好的方法。我怎么能避免不得不.Select
表单?
Sub ReportFormatter()
Columns("BS:BS").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Columns("X:X").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet2").Select
Range("B1").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Columns("Y:Y").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet2").Select
Range("C1").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Columns("H:H").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet2").Select
Range("D1").Select
ActiveSheet.Paste
答案 0 :(得分:5)
Sub CopyCols()
Sheets("Sheet1").Columns("X:X").Copy Destination:=Sheets("Sheet2").Range("B1")
Sheets("Sheet1").Columns("Y:Y").Copy Destination:=Sheets("Sheet2").Range("C1")
Sheets("Sheet1").Columns("H:H").Copy Destination:=Sheets("Sheet2").Range("D1")
End Sub
答案 1 :(得分:1)
Sub ReportFormatter()
With Sheets("Sheet1")
.Columns("BS").Copy Sheets("Sheet2").Range("A1")
.Columns("X").Copy Sheets("Sheet2").Range("B1")
.Columns("Y").Copy Sheets("Sheet2").Range("C1")
.Columns("H").Copy Sheets("Sheet2").Range("D1")
End With
End Sub
答案 2 :(得分:1)
或者简单地说:
Sub CopyCols()
Sheets("Sheet2").Columns("B:B") = Sheets("Sheet1").Columns("X:X")
Sheets("Sheet2").Columns("C:C") = Sheets("Sheet1").Columns("Y:Y")
Sheets("Sheet2").Columns("D:D") = Sheets("Sheet1").Columns("H:H")
End Sub