excel vba需要控制,检查是否有空单元格

时间:2014-02-09 10:05:00

标签: excel excel-vba excel-2007 vba

    Private Function test()
    Dim S1 As String, S2 As String

    Dim lRow As Long, i As Long
    Dim ws As Worksheet

    Set ws = ActiveWorkbook.Sheets("pppdp")
    With ws
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = 19 To lRow
    End Function

嗨,我有excel工作表用于将表导出到 xml ,所以我需要控制来检查A到R范围内是否有空单元格,我从这开始但是我停在那里并且不要我知道接下来该做什么。

1 个答案:

答案 0 :(得分:1)

  

在A到R的范围内是否有空单元?

逻辑是检查总细胞数是否等于填充的细胞总数。

喜欢这个吗?

Sub Sample()
    If test = False Then
        MsgBox "Range A to R has empty cells"
    Else
        MsgBox "No Empty Cells"
    End If
End Sub

Private Function test() As Boolean
    Dim lRow As Long
    Dim ws As Worksheet

    Set ws = ActiveWorkbook.Sheets("pppdp")

    With ws
        If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
            lRow = .Range("A:R").Find(What:="*", _
                          After:=.Range("A1"), _
                          Lookat:=xlPart, _
                          LookIn:=xlFormulas, _
                          SearchOrder:=xlByRows, _
                          SearchDirection:=xlPrevious, _
                          MatchCase:=False).Row
        Else
            lRow = 1
        End If

        test = Application.WorksheetFunction.CountA(.Range("A1:R" & lRow)) _
             = .Range("A1:R" & lRow).Cells.Count
    End With
End Function

enter image description here