看看这是否有帮助。
Sub myColumns()
Dim wS As Worksheet
Dim wT As Worksheet
Dim rS As Range, rT As Range, Cel As Range
Dim l As Long
Application.ScreenUpdating = False
Set wS = ThisWorkbook.Worksheets("Settings")
Set wT = ThisWorkbook.Worksheets("Data")
'source range
With wS
Set rS = .Range("AE1", .Cells(.Rows.Count, "AE:AE").End(xlUp))
End With
'target range
With wT
Set rT = .Range("A8", .Cells(8, .Columns.Count).End(xlToLeft))
End With
'add source items to target sheet
For Each Cel In rS
If IsError(Application.Match(Cel.Value, rT, 0)) Then 'doesn't exist in target, add
'add to right of existing data
wT.Cells(8, wT.Columns.Count).End(xlToLeft).Offset(, 1).Value = Cel.Value
End If
Next Cel
'clear target sheet of source non-matches
For l = rT.Columns.Count To 1 Step -1
If IsError(Application.Match(rT(l).Value, rS, 0)) Then 'doesn't exist in source, delete
rT(l).EntireColumn.Delete
End If
Next l
Application.ScreenUpdating = True
End Sub