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

giz*_*gok 15 excel vba

我有一张表,其中我有来自两个不同来源的数据.我们之间有一个空行.我想把这个空白行作为我的分隔符.如何找出整行是否为空白.

Got*_*bbs 22

如果你正在说一个字面的整行,那么类似的代码应该可以工作(只要在任何单元格中都没有公式或空格):

If Application.CountA(ActiveCell.EntireRow)=0 Then
     MsgBox "Row Empty"
     Exit Sub
End If
Run Code Online (Sandbox Code Playgroud)

否则,对于一行范围:

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
Run Code Online (Sandbox Code Playgroud)

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


Jay*_*Jay 13

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
Run Code Online (Sandbox Code Playgroud)