Sub CorrectOrder()
Dim strC As String
Dim cl As Range
strC = 0
For Each cl In Workbooks("Report.xls").Worksheets("Sheet1").Range("A1:AZ1")
If cl.Value = "Sector" Then
strC = cl.Column
Workbooks("Report.xls").Worksheets("Sheet1").Range(strC).Select
Selection.Copy
Workbooks("Report.xls").Worksheets("Sheet2").Range ("A1")
Selection.Paste
End If
Next cl
End Sub
答案 0 :(得分:1)
我这样做:
Sub CorrectOrder()
Dim searchRange As Range, cl As Range
Set searchRange = Workbooks("Report.xls").Worksheets("Sheet1").Range("A1:AZ1")
For Each cl In searchRange
If cl = "Sector" Then
Workbooks("Report.xls").Worksheets("Sheet1").Columns(cl.Column).Copy Destination:=Workbooks("Report.xls").Worksheets("Sheet2").Range("A1")
End If
Next cl
End Sub
基本上使用Columns
来引用该列。并且在复制和粘贴时不要费心。