我是新手,需要帮助解决这个问题。我试图在excel上使用此代码来更改单元格的颜色和文本,但它不适用于合并的单元格。如何使它适用于合并的单元格?
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("$C$17:$C$80")) Is Nothing Then Exit Sub
Select Case Target
Case ""
Target = "Priority 1"
Target.Interior.ColorIndex = 3
Case "Priority 1"
Target = "Priority 2"
Target.Interior.ColorIndex = 6
Case "Priority 2"
Target = "Priority 3"
Target.Interior.ColorIndex = 45
Case Else
Target = ""
Target.Interior.ColorIndex = 15
End Select
Cancel = True
End Sub
答案 0 :(得分:2)
超级关闭,只需更改一行:Select Case Target
至Select Case Target.Item(1)
完整代码:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("$C$17:$C$80")) Is Nothing Then Exit Sub
Select Case Target.Item(1)
Case ""
Target = "Priority 1"
Target.Interior.ColorIndex = 3
Case "Priority 1"
Target = "Priority 2"
Target.Interior.ColorIndex = 6
Case "Priority 2"
Target = "Priority 3"
Target.Interior.ColorIndex = 45
Case Else
Target = ""
Target.Interior.ColorIndex = 15
End Select
Cancel = True
End Sub
结果:
你可以在这里看到我有一个从C23到C26的合并区域