0

我有一个 Sud,它告诉我一列是否有空白单元格。

如果它是空白的,有没有办法也得到单元格的位置,可能有数千行,可能有一两个空白单元格,即使你知道它在那里也很容易错过。

谢谢

Sub CountBlankCellsComments()

Dim Lastrow As Long

Sheets("Comments").Select
With Sheets("Comments")
Lastrow = .Range("A" & .Rows.Count).End(xlUp).Row
End With

If WorksheetFunction.CountBlank(Range("A2:E" & Lastrow)) = 0 Then

            MsgBox "There Are (0) Blank Cells For ""Comments"" Sheet"
        Else

MsgBox "For Comments Sheet There are:" & vbCrLf & vbLf & _
"(" & WorksheetFunction.CountBlank(Range("A2:A" & Lastrow)) & ") Blank Cells in Column A" & vbCrLf & vbLf & _
"(" & WorksheetFunction.CountBlank(Range("B2:B" & Lastrow)) & ") Blank Cells in Column B" & vbCrLf & vbLf & _
"(" & WorksheetFunction.CountBlank(Range("C2:C" & Lastrow)) & ") Blank Cells in Column C" & vbCrLf & vbLf & _
"(" & WorksheetFunction.CountBlank(Range("D2:D" & Lastrow)) & ") Blank Cells in Column D" & vbCrLf & vbLf & _
"(" & WorksheetFunction.CountBlank(Range("E2:E" & Lastrow)) & ") Blank Cells in Column E"

End If

End Sub
4

3 回答 3

1
Dim blanks As Range

With Worksheets("Comments")
  On Error Resume Next
  Set blanks = Application.Intersect(.Range("A2", .UsedRange.SpecialCells(xlCellTypeLastCell)), .Range("A:E")).SpecialCells(xlCellTypeBlanks)
  On Error GoTo 0
End With

If blanks Is Nothing Then
  MsgBox "There Are (0) Blank Cells For ""Comments"" Sheet"
Else

  blanks.Select

  MsgBox "For Comments Sheet There are (" & blanks.Cells.Count & ") Blank Cells:" & vbNewLine & vbNewLine & _
    blanks.Address

End If
于 2013-06-16T17:24:52.797 回答
1

只需在您的代码中添加这一行:

MsgBox "BlankCells are:" & Range("A2:E" & Lastrow).SpecialCells(xlCellTypeBlanks).Address 
于 2013-06-16T19:15:58.883 回答
0

这个怎么样:

Sub ShowBlanks()
    Dim data As Range, cl As Range, blanks As String

        Set data = Range("A1:E" & Range("A" & Rows.Count).End(xlUp).Row)
        blanks = vbNullString

        For Each cl In data
            If cl.Value = vbNullString Then
                blanks = blanks & cl.Address & vbCrLf & vbLf
            End If
        Next cl

        MsgBox "These cell are empty:" & vbCrLf & vbLf & blanks
End Sub
于 2013-06-16T17:19:29.073 回答