VBA 突出显示单元格的多个条件
VBA Highlight Cells multiple criteria
我正在尝试在电子表格中创建一个代码,当满足单元格 E13="Country" 和 F13="State" 上的 2 个不同条件时,该代码将突出显示单独的单元格区域 (A28:D28) , F13 有一个依赖于 E13 上的值的验证,它也有一个数据验证。到目前为止我有这段代码,我认为它根本没有意义。
Set A = Range("E13")
If Not Intersect(Target, A) Is Nothing Then
If A = "Country" Then
For Each A In Range("E13")
If A.Offset(0, 1) = "State" Then
A.Interior.ColorIndex = 5
End If
End If
End If
此代码将用于跨多个部分的多种组合以突出显示多个范围,但我认为我可以设法复制粘贴和更改范围,很抱歉,我的 VBA 技能不是那么好。
当在一组单独的范围上满足特定条件时,所有这些都在 returns MsgBoxs 的代码之后。
谢谢!
这是完成工作的最基本的代码行:
Sub temp()
If Range("E13").Value = "Country" And Range("F13").Value = "State" Then Range("A28:D28").Interior.ColorIndex = 5
End Sub
如果您需要 运行 的 E13 更改代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E13")) Is Nothing Then
If Range("E13").Value = "Country" And Range("F13").Value = "State" Then Range("A28:D28").Interior.ColorIndex = 5
'Copy and past the line above with the other criteria you may need
End If
End Sub
如何在运行填充颜色之前清除整个颜色范围并检查E13或F13是否发生变化:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E13:F13")) Is Nothing Then
Range("A28:D38").Interior.Pattern = xlNone 'replace A28:D38 with your range
If Range("E13").Value = "Country" And Range("F13").Value = "State" Then Range("A28:D28").Interior.ColorIndex = 5
'Copy and past the line above with the other criteria you may need
End If
End Sub
我正在尝试在电子表格中创建一个代码,当满足单元格 E13="Country" 和 F13="State" 上的 2 个不同条件时,该代码将突出显示单独的单元格区域 (A28:D28) , F13 有一个依赖于 E13 上的值的验证,它也有一个数据验证。到目前为止我有这段代码,我认为它根本没有意义。
Set A = Range("E13")
If Not Intersect(Target, A) Is Nothing Then
If A = "Country" Then
For Each A In Range("E13")
If A.Offset(0, 1) = "State" Then
A.Interior.ColorIndex = 5
End If
End If
End If
此代码将用于跨多个部分的多种组合以突出显示多个范围,但我认为我可以设法复制粘贴和更改范围,很抱歉,我的 VBA 技能不是那么好。 当在一组单独的范围上满足特定条件时,所有这些都在 returns MsgBoxs 的代码之后。
谢谢!
这是完成工作的最基本的代码行:
Sub temp()
If Range("E13").Value = "Country" And Range("F13").Value = "State" Then Range("A28:D28").Interior.ColorIndex = 5
End Sub
如果您需要 运行 的 E13 更改代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E13")) Is Nothing Then
If Range("E13").Value = "Country" And Range("F13").Value = "State" Then Range("A28:D28").Interior.ColorIndex = 5
'Copy and past the line above with the other criteria you may need
End If
End Sub
如何在运行填充颜色之前清除整个颜色范围并检查E13或F13是否发生变化:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E13:F13")) Is Nothing Then
Range("A28:D38").Interior.Pattern = xlNone 'replace A28:D38 with your range
If Range("E13").Value = "Country" And Range("F13").Value = "State" Then Range("A28:D28").Interior.ColorIndex = 5
'Copy and past the line above with the other criteria you may need
End If
End Sub