Excel特定列提取
我一直在尝试从大量不需要的列中提取Excel工作表中的某些列。我一直在运行以下脚本:Excel特定列提取,excel,excel-2010,vba,Excel,Excel 2010,Vba,我一直在尝试从大量不需要的列中提取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
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
它很快(而且很脏),但以下代码将满足您的需要:
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
一组单元格将自身均匀化为从左到右/从上到下的排列。如果您希望重新构造目标,则需要执行多个操作。@Sage Mohan您可以尝试我的代码(如下),这并不理想,但它会帮您完成任务case@ShaiRado代码是有效的。我今天测试了一下。谢谢。一组细胞会将自身均匀化为从左到右/从上到下的排列。如果您希望重新构造目标,则需要执行多个操作。@Sage Mohan您可以尝试我的代码(如下),这并不理想,但它会帮您完成任务case@ShaiRado代码是有效的。我今天测试了一下。非常感谢。