2014-02-09 101 views
3
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空單元格,我開始有了這個,但我停在那裏,不知道接下來該做什麼。Excel VBA中需要控制,將檢查是theere空單元格

回答

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

+0

的偉大工程,謝謝。這將是很好,如果它可以用紅色標記空單元格,這將有助於很多 –

+0

我可以給你答案,但你想先試試嗎? ;)閱讀'Range.SpecialCells Method' –

+0

內置的Excel幫助,說實話我沒有一個線索我應該做的:),所以如果u幫助我,我將不勝感激 –

相關問題