第一次出现非空白单元格 vba

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2962509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:41:22  来源:igfitidea点击:

first Occurrence Of Non Blank Cell vba

excelvba

提问by BumbleBee

I am trying to write VBA code which works on my Excel sheet.

我正在尝试编写适用于我的 Excel 工作表的 VBA 代码。

Range("A65536").End(xlUp).Row gives me the row number of the last non blank cell. similarly i am trying to get the row number of the first non blank cell in that particular column. Thanks in advance. madhu

Range("A65536").End(xlUp).Row 给我最后一个非空白单元格的行号。同样,我试图获取该特定列中第一个非空白单元格的行号。提前致谢。马杜

回答by goggin13

You can use the same function, just check to see if the first row is blank.

您可以使用相同的功能,只需检查第一行是否为空。

Dim firstRow as Integer

If ActiveSheet.Range("A1").value = "" Then
    firstRow = ActiveSheet.Range("A1").End(xlDown).Row
Else
    firstRow = 1
End If

If the first row is not blank and you use the End(xlDown)call you won't get the first non-empty cell you will get the last non-empty cell before the first blank cell.

如果第一行不为空并且您使用该End(xlDown)调用,您将不会获得第一个非空单元格,您将获得第一个空白单元格之前的最后一个非空单元格。

回答by Michael

You can also use the IsEmpty(cell) function, which returns a boolean true/false.

您还可以使用 IsEmpty(cell) 函数,该函数返回布尔值 true/false。