将通用列复制到单独的工作表

我试了下面的代码,将整个列从一个页面复制到其他页面。

我有一个共同的标题,六月分散在表单中,我只想复制列表,标题名称为“六月”在单独的表中一个接一个。

EG如果列A,C,L,M的列标题为六月份,则在下一张表格中,这些列表只应复制为A,B,C,D。

Sheets("sheet1").Select June = WorksheetFunction.Match("Description", Rows("1:1"), 0) Sheets("sheet1").Columns(June).Copy Destination:=Sheets("sheet2").Range("A1") 

以下可能有帮助:

 Option Explicit Sub Demo() Dim srcSht As Worksheet, destSht As Worksheet Dim headerRng As Range, cel As Range, copyRng As Range Dim lastCol As Long, col As Long Set srcSht = ThisWorkbook.Sheets("Sheet1") 'Sheet1 Set destSht = ThisWorkbook.Sheets("Sheet2") 'Sheet2 lastCol = srcSht.Cells(1, srcSht.Columns.Count).End(xlToLeft).Column 'last column of Sheet1 With srcSht For Each cel In .Range(.Cells(1, 1), .Cells(1, lastCol)) 'loop through each header name in Sheet1 If cel = "June" Then 'check header is "June" If copyRng Is Nothing Then 'assign range to copy Set copyRng = .Columns(cel.Column) Else Set copyRng = Union(copyRng, .Columns(cel.Column)) End If End If Next cel End With copyRng.Copy destSht.Range("A1") 'copy and paste desired columns End Sub