合并Excel中的范围 [英] Range in Merging Excel
本文介绍了合并Excel中的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个我不明白的代码。有人可以向我解释这段代码:
I have a code which I do not understand. Can someone explain to me this code:
Range("A2:IV" & Range("A65536").End(xlUp).Row).Copy
可在此代码中找到。
It can be found in this codes.
<pre lang="vb">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")
Dim strWSName As String
strWSName = InputBox("Enter the file path of Excel Files to merge")
'change folder path of excel files here
Set dirObj = mergeObj.GetFolder(strWSName)
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
推荐答案
范围(A2:IV和范围(A65536)。结束(xlUp).Row)。复制
这是你在工作表中动态选择/复制范围的方法。
它使用A列数据的最后一行作为第IV栏中的最后一个单元格
Range("A2:IV" & Range("A65536").End(xlUp).Row).Copy
this is how you dynamically select/copy a range in a worksheet.
it uses the last row that has data in column A to be the last cell in column IV
Range.End Property [ ^ ] - 返回一个Range对象,该对象表示包含源范围的区域末尾的单元格。相当于按下END +向上箭头,结束+向下箭头,结束+左箭头或结束+向右箭头。
Range.End Property[^] - Returns a Range object that represents the cell at the end of the region that contains the source range. Equivalent to pressing END+UP ARROW, END+DOWN ARROW, END+LEFT ARROW, or END+RIGHT ARROW.
Range("A2:IV" & Range("A65536").End(xlUp).Row).Copy
以上代码表示:
范围(A65536)。结束(xlUp)
- 查找首先不是A列中的空单元格
.Row
- 获取行数
,最后......
.Copy
- 复制已选择范围;)
Above code means:
Range("A65536").End(xlUp)
- find first not empty cell in A column
.Row
- get the number of row
and finally...
.Copy
- copy "selected" range ;)
这篇关于合并Excel中的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文