本文介绍了使用Excel VBA查找最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于如何在excel vba中找到最后一行的查询.我目前正在从事一个项目,该项目需要我找到此特定工作表的最后一行,称为Annex 1A.

I have an inquiry on how to find the last row in excel vba. I am currently working on a project which requires me to find the last row of this particular worksheet called Annex 1A.

工作表的片段图像如下所示:

A snip image of the worksheet is shown below:

例如,从上面的图像中,Row 32Row 33包含空值,我想导出正在使用的行的总数.

For instance, from the image above, Row 32 and Row 33 contain empty values and I would like to derive the total of rows that is being used.

我尝试了以下方法:

方法1

LastRow = Sheets("Annex 1A").Cells.Find(What:="*", _
                  After:=Sheets("Annex 1A").Range("B1"), _
                  Lookat:=xlPart, _
                  LookIn:=xlFormulas, _
                  SearchOrder:=xlByRows, _
                  SearchDirection:=xlPrevious, _
                  MatchCase:=False).Row

方法2

  LastRow = Sheets("Annex 1A").Range("B" & Sheets("Annex1A").Rows.Count).End(xlUp).Row

LastRow值将始终返回31而不是33.我还有其他方法可以得出33的值吗?

The LastRow value would always return 31 instead of 33. Is there any other way for me to derive the value of 33?

推荐答案

这种方法在我需要的时间中有90%的时间对我有效:

This method has worked for me in like 90% of the times I needed it:

Lastrow = Sheets("Annex 1A").UsedRange.SpecialCells(xlCellTypeLastCell).row

这篇关于使用Excel VBA查找最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 17:22