【发布时间】:2015-06-17 02:57:19
【问题描述】:
我有一些文本数据要搜索并突出显示。
它是按频率组织(并分成组)的每日/每月/年度任务......所以我有一个单独的盒子用于每日、每周等。
每个组有 3 列...“类型”、“频率”和“描述”。
我有一个Listbox,其中包含所有类型的任务,当您选择一个并按下按钮时,它会突出显示与该任务相对应的所有任务...
到目前为止,我能够做到这一点的唯一方法是通过 VBA 条件格式。
但它只突出显示任务的类型,我无法弄清楚如何让它同时突出显示它旁边的两列......
我正在探索如何通过搜索来做到这一点,但无法正确实现。
这是我的代码
Private Sub CommandButton1_Click()
Dim typeSelection As String
Dim rng As Range
Set rng = Sheet4.Range("$E$3:$O$23")
typeSelection = ListBox1.Text
Debug.Print rng.Address
With rng
.FormatConditions.Delete
.FormatConditions.Add Type:=xlTextString, String:=typeSelection, _
TextOperator:=xlBeginsWith
.FormatConditions(1).Interior.Color = RGB(255, 0, 0)
.FormatConditions(1).Font.Bold = True
'Debug.Print .FormatConditions(1).AppliesTo.Address
'.FormatConditions(1).ModifyAppliesToRange .FormatConditions(1).AppliesTo.Offset(RowOffSet:=0, ColumnOffset:=2)
'.FormatConditions(1).Interior.Color = RGB(255, 0, 0)
'.FormatConditions(1).Font.Bold = True
'Debug.Print .FormatConditions(1).AppliesTo.Address
End With
Dim rCell As Range
Dim cRng As Range
For Each rCell In rng.Cells
Set cRng = rCell
Debug.Print rCell.Address
isConditionallyFormatted (rCell)
Next rCell
End Sub
【问题讨论】:
-
您是否尝试过使用数据验证下拉菜单进行常规条件格式(非 vba),或者不会达到您想要的结果。据我所知,它会(如果是,我可以发布解决方案)
-
对不起,我没有尝试探索数据验证。我是一个巨大的 excel 菜鸟
-
如果您验证我对您的问题的理解,我将给出一个解决方案:您有“主要”列,每日、每月和每年的任务。每个有 3 列宽,带有标题类型、频率和描述。 You want to have ONE dropdown (or one per major column/group??) with all task types (are these predefined in some list somewhere?) and when selected, it shall highlight the type, frequency and description of all tasks with that type .正确的?而且,A:C、D:F 和 G:I 中的这些组是否在同一张纸上?
-
我的朋友i.imgur.com/ihmkYbC.png看起来像这样
标签: vba excel conditional-formatting