条件格式与案例多个选择

阿德里安

我有一个像下面这样的 VBA,但是当我复制超过 1 个单元格时,由于多选,我收到一个错误。

是否可以执行一个动作,让 Case 一个接一个地查看选定的单元格?或者我有错误的声明?

Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("$G$8:$OA$92")) Is Nothing Then

    With Target
     Select Case .Value
      Case Is = "Weekend"
          .Interior.ColorIndex = 48
      Case Is = "VRIJ", "ADV"
          .Interior.ColorIndex = 6
     End Select
End With
End If
End Sub
用户4039065

循环遍历相交中的单元格。

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("G8:OA92")) Is Nothing Then
        on error goto meh
        application.enableevents = false
        dim t as range
        for each t in Intersect(Target, Range("G8:OA92"))
            With t
                Select Case lcase(.Value2)
                    Case "weekend"
                        .Interior.ColorIndex = 48
                    Case "vrij", "adv"
                        .Interior.ColorIndex = 6
                    case else
                        .interior.pattern = xlnone
                End Select
            End With
        next t 
    End If 
meh:
    application.enableevents = true
End Sub

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章