vba - 如何为空单元格上色

标签 vba excel syntax-error

效果很好,但他没有使用标签的最后一行

你能帮我发现我的错误吗!

         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

最佳答案

编辑:更新为显示如何突出显示空白单元格

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

编辑2:
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

关于vba - 如何为空单元格上色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33397041/

相关文章:

excel - 如何将包含中文字符的 Excel 文件导出为 CSV?

JavaScript 语法错误

vba - 更改用户窗体中的选项按钮选择

python - openpyxl 和 excel 宏

excel - 使用 VBA 在多行中插入验证列表

excel - 如何在 Angular 8 中下载 excel 文件作为 API 响应

syntax-error - 仅删除 '@apply' 的 Sublime 语法高亮

javascript - Vimeo slider 脚本 - SyntaxError : JSON. 解析:意外字符

vba - 检查值是否可迭代vba

excel - 在文本框中使单词加粗