Excel专用列提取
我一直试图从许多不需要的列中提取Excel表格中的某些列。 我一直在运行下面的脚本:
Public Sub extractCol() Set range1 = Range("A:A, BI:BI, C:C, L:L") range1.Copy Set newbook = Workbooks.Add ActiveCell.PasteSpecial Paste:=xlPasteValues End Sub
这个公式提取数据然而,输出结果如下:
Column A Column C Column L Column BI
当我需要的输出是:
Column A Column BI Column C Column L
如何更改代码以获得所需的输出?
这是快速(和脏),但下面的代码将得到你想要的:
Public Sub extractCol() Dim newbook As Workbook Dim ShtSource As Worksheet Dim ShtDest As Worksheet ' modify Sheet 1 to your Source sheet name Set ShtSource = ThisWorkbook.Sheets("Sheet6") Set newbook = Workbooks.Add ' modify Sheet 1 to your Destination sheet name Set ShtDest = newbook.Sheets("Sheet1") ShtSource.Columns("A:A").Copy Destination:=ShtDest.Columns(1) ShtSource.Columns("BI:BI").Copy Destination:=ShtDest.Columns(2) ShtSource.Columns("C:C").Copy Destination:=ShtDest.Columns(3) ShtSource.Columns("L:L").Copy Destination:=ShtDest.Columns(4) End Sub