Finding last column and then finding the last row in that column

人盡茶涼 提交于 2019-12-11 09:53:27

问题


I need to find the last column in a worksheet and then find the last row in that particular column. For last column I am using this:

lastcol = .Cells(1, .Columns.count).End(xlToLeft).Column
last_row = Range((Cells(Rows.count), lastcol).Find("*", after:=r, LookIn:=x1values, lookat:=x1part, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)

Here is snapshot of the worksheet:

Can some also help me with putting all the data I want to save in an array 2 dimensional and then pasting the data on a Excel sheet?


回答1:


Here is how:

lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
lastrow = .Cells(.Rows.Count, lastcol).End(xlUp).Row

.Cells(lastrow + 1, lastcol).Resize(UBound(myarray)) = myarray

.

Let's assume the batch data are sourced in Sheet1 beginning in cell A1, here is how to make the 2D array:

Dim myarray

myarray = Sheet1.[a1].CurrentRegion 


来源:https://stackoverflow.com/questions/33545516/finding-last-column-and-then-finding-the-last-row-in-that-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!