vba 如何在excel彻底vba中找出整行是否为空白

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3628057/
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-08 10:45:11  来源:igfitidea点击:

How to find out if an entire row is blank in excel thorough vba

excelvba

提问by gizgok

I have a sheet in which I have data from two different sources.I've a blank row between them.I want to make this blank row as my delimiter.How can I find out if the entire row is blank or not.

我有一张工作表,其中包含来自两个不同来源的数据。它们之间有一个空白行。我想将此空白行作为我的分隔符。如何确定整行是否为空白。

回答by GotDibbs

If you're talking a literal entire row then code similar to this should work (so long as there are no formulas or spaces present in any of the cells as well):

如果你说的是整行文字,那么与此类似的代码应该可以工作(只要任何单元格中也不存在公式或空格):

If Application.CountA(ActiveCell.EntireRow)=0 Then
     MsgBox "Row Empty"
     Exit Sub
End If

Otherwise, for a range from a row:

否则,对于来自一行的范围:

Dim neValues As Range, neFormulas As Range, MyRange As Range

Set MyRange = Columns("C:AA")

On Error Resume Next
Set neValues = Intersect(ActiveCell.EntireRow.SpecialCells(xlConstants), MyRange)
Set neFormulas = Intersect(ActiveCell.EntireRow.SpecialCells(xlFormulas), MyRange)
On Error GoTo 0

If neValues Is Nothing And neFormulas Is Nothing Then
    MsgBox "Nothing There"
Else
    MsgBox "Something's There"
End If

(Source: http://www.ozgrid.com/forum/showthread.php?t=26509&page=1)

(来源:http: //www.ozgrid.com/forum/showthread.php?t=26509& page=1

回答by Jay

WorksheetFunction.CountA(), as demonstrated below:

WorksheetFunction.CountA(),如下图所示:

Dim row As Range
Dim sheet As Worksheet
Set sheet = ActiveSheet

For i = 1 To sheet.UsedRange.Rows.Count

    Set row = sheet.Rows(i)
    If WorksheetFunction.CountA(row) = 0 Then
        MsgBox "row " & i & " is empty"
    End If

Next i