如何在MS Excel中合并选定的列 [英] How to merge selected columns in MS Excel
本文介绍了如何在MS Excel中合并选定的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码,它将合并所选文件夹中的所有文件。
I have this code where it will merge all the files in a selected folder.
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
'change folder path of excel files here
Set dirObj = mergeObj.GetFolder("C:\Documents and Settings\MergeData")
Set fileObj = dirObj.Files
For Each everyObj In fileObj
Set bookList = Workbooks.Open(everyObj)
'change "A2" with cell reference of start point for every files here
'for example "B3:IV" to merge all files start from columns B and row 3
'If you're files using more than IV column, change it to the latest column
'Also change "A" column on "A65536" to the same column as start point
Range("A2:IV" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
'Do not change the following column. It's not the same column as above
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
bookList.Close
Next
End Sub
但我只想将选定的列复制到新工作簿中。我不知道用什么函数或代码来实现这个目的。
例如:
工作簿1
姓名,地址,邮政编码,年龄
工作簿2
姓名,地址,年龄,职业
在新工作簿中我希望列只有
只能复制名称和地址
But I only want selected columns to be copied to the new workbook. I don't know what function or code to use to make that happen.
Example:
Workbook1
Name, Address, Postal Code, Age
Workbook2
Name, Address, Age, Occupation
In the new workbook I want the columns with
Name and Address only to be copied
推荐答案
试试这些链接
http://en.kioskea .net / forum / affich-30153-copy-rows-based-on-a-condition [ ^ ]
http://nerds-central.blogspot.in/2007/01/excel-copy-and-paster-cellsrowscolumns.html [ ^ ]
Try these links
http://en.kioskea.net/forum/affich-30153-copy-rows-based-on-a-condition[^]
http://nerds-central.blogspot.in/2007/01/excel-copy-and-paster-cellsrowscolumns.html[^]
这篇关于如何在MS Excel中合并选定的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文