以下是为您编写的相关 VBA 代码示例: ```vb Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range) Dim rng As Range Dim cellValue As Variant If Target.Address = "$C$3" Then Set rng = Range("C5:L30000") For Each cell In rng cellValue = cell.Value If cellValue >= 6 Then cell.Interior.Color = Choose(cellValue, RGB(255, 255, 0), RGB(0, 102, 204), RGB(0, 0, 0), RGB(255, 128, 0), RGB(0, 255, 255), RGB(0, 0, 255), RGB(128, 128, 128), RGB(255, 0, 0), RGB(128, 0, 0), RGB(128, 128, 0)) End If Next cell ElseIf Target.Address = "$D$3" Then Set rng = Range("C5:L30000") For Each cell In rng cellValue = cell.Value If cellValue <= 5 Then cell.Interior.Color = Choose(cellValue, RGB(255, 255, 0), RGB(0, 102, 204), RGB(0, 0, 0), RGB(255, 128, 0), RGB(0, 255, 255), RGB(0, 0, 255), RGB(128, 128, 128), RGB(255, 0, 0), RGB(128, 0, 0), RGB(128, 128, 0)) End If Next cell ElseIf Target.Address = "$E$3" Then Set rng = Range("C5:L30000") For Each cell In rng cellValue = cell.Value If cellValue Mod 2 <> 0 Then cell.Interior.Color = Choose(cellValue, RGB(255, 255, 0), RGB(0, 102, 204), RGB(0, 0, 0), RGB(255, 128, 0), RGB(0, 255, 255), RGB(0, 0, 255), RGB(128, 128, 128), RGB(255, 0, 0), RGB(128, 0, 0), RGB(128, 128, 0)) End If Next cell ElseIf Target.Address = "$F$3" Then Set rng = Range("C5:L30000") For Each cell In rng cellValue = cell.Value If cellValue Mod 2 = 0 Then cell.Interior.Color = Choose(cellValue, RGB(255, 255, 0), RGB(0, 102, 204), RGB(0, 0, 0), RGB(255, 128, 0), RGB(0, 255, 255), RGB(0, 0, 255), RGB(128, 128, 128), RGB(255, 0, 0), RGB(128, 0, 0), RGB(128, 128, 0)) End If Next cell End If End Sub ``` 额外需要注意的逻辑点: 1. 确保数据区的范围准确,以免出现颜色标记错误。 2. 注意处理数据类型,避免因数据类型不匹配导致判断错误。 3. 代码运行前最好备份数据,以防意外情况导致数据丢失。 [2024-12-07 18:07:56 | AI写代码神器 | 942点数解答]