如何着色空单元格

时间:2015-10-28 16:55:49

标签: vba excel-vba syntax-error excel

它运作良好,但他没有采取标签的最后一行

你可以帮我找到我的错误!

         Dim c As Range

Dim MaPlage As Range

   For q = 2 To ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row

Set MaPlage = Range("A:H, J:R").Rows(q)
 For Each c In MaPlage.Cells
If Len(c.Value) = 0 Then c.Interior.Color = vbYellow

If CStr(ActiveSheet.Cells(q, 31).Value) = "Completed - Appointment made / Complété - Nomination faite" _
     And WorksheetFunction.CountIf(MaPlage, "") = 0 Then
    Select Case UCase(ActiveSheet.Cells(q, 14).Value)
        Case "INA_CIN"
            ActiveSheet.Cells(q, 42).Value = "XX"
    End Select
End If

Next c

Next q

1 个答案:

答案 0 :(得分:3)

已更新

修改以显示如何突出显示空单元格

Dim MaPlage As Range, c As Range

Set MaPlage = Sheet1.Range(Replace("A#:H#,J#:R#", "#", q)) 

For Each c In MaPlage.Cells '<<EDIT2 to remove extra space
    If Len(c.Value) = 0 Then c.Interior.Color = vbRed
Next c

EDIT2:

Sub TT()

    Const S As String = "Completed - Appointment made / Complété - Nomination faite"

    Dim MaPlage As Range, c As Range, rw As Range
    Dim q As Integer, blanks As Long

       For q = 2 To ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row

           Set rw = Sheet1.Rows(q)
           Set MaPlage = rw.Range("A1:H1,J1:R1")
           blanks = 0
           For Each c In MaPlage.Cells
               If Len(c.Value) = 0 Then
                  c.Interior.Color = vbRed
                  blanks = blanks + 1
               End If
           Next c

           If CStr(rw.Cells(31).Value) = S And blanks = 0 Then
               Select Case UCase(rw.Cells(14).Value)
                Case "INA_CIN"
                    rw.Cells(42).Value = "XX"
                End Select
           End If

    Next q
End Sub