lastrow和excel表. [英] lastrow and excel table.
问题描述
我试图定义一个lastrow代码,该代码将返回excel表中最后一个非空单元格的最后一行值. (其格式为表格)
I have tried to define a lastrow code that would return the last row value of the last non empty cell in a excel table. (ITS FORMATTED AS A TABLE)
我的exceltable的COL A值从1到1005,COL B值从1到414,COL C的值从414到1005.
My exceltable have values in COL A from 1 to 1005, COL B from 1 to 414 and in COL C from 414 to 1005.
我想要的是有一个lastrow代码返回414,一个返回1005.我遇到的问题是,因为它在表中.我的密码
What i want is to have one lastrow code that returns 414 and one that returns 1005. The problem i get is that because it is in a table. my codes
lastrow3 = ThisWorkbook.Worksheets("DataÖnskemål").Range("A" & Rows.Count).End(xlUp).Row
lastrow2 = ThisWorkbook.Worksheets("DataÖnskemål").Range("B" & Rows.Count).End(xlUp).Row
两个都返回1005.我可以在桌子上解决这个问题吗?还是某种格式问题?
Both return 1005. Can i get around this with my table or is it a formating issue of some sort?
最诚挚的问候和预先的感谢 /D
Best regards and thanks in advance /D
推荐答案
如果工作表上excel表下方有数据,您将遇到问题.在Excel表格中查找最后一行时,最好参考表格列.
You will have issue if there is data below the excel table on the sheet. It's always better to refer the table column while finding the last row in an excel table.
Sub FindLastRowInExcelTableColAandB()
Dim lastRow1 As Long, lastRow2 As Long
Dim ws As Worksheet
Set ws = Sheets("DataÖnskemål")
'Assuming the name of the table is "Table1"
lastRow1 = ws.ListObjects("Table1").Range.Columns(1).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lastRow2 = ws.ListObjects("Table1").Range.Columns(2).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End Sub
这篇关于lastrow和excel表.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!