在这里完成VBA / Excel初学者......
我试图让单元格的背景颜色根据在该单元格中选择的下拉选项而改变,但我在交叉语句中得到了类型匹配错误。有人可以向我解释为什么好吗?
代码如下:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range
Set myRange = Range("C6:G14")
If Intersect(Target, myRange) Then
MsgBox "Success"
Select Case Target.Value
Case "YES"
mycolor = "#84ff84"
Case "NO"
mycolor = "#fc3c3c"
Case Else
mycolor = xlNone
End Select
End If
Target.Interior.ColorIndex = mycolor
End Sub
答案 0 :(得分:0)
试试这个,
If Not Application.Intersect(Target, Me.Range("C6:G14")) Is Nothing Then