how to colors empty cells

ε祈祈猫儿з 提交于 2019-12-14 04:06:59

问题


it works good but he doesn't take the last line of the tab

can u please help me to find my errors !

         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:


EDIT: updated to show how to highlight empty cells

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


来源:https://stackoverflow.com/questions/33397041/how-to-colors-empty-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!