首页 > 解决方案 > 我如何将条件格式应用于单元格的值而不是该值的外观?

问题描述

正如标题所示,我正在处理条件格式问题。

条件格式允许我根据公式更改单元格的外观(填充颜色、文本颜色),但是有什么方法可以更改文本本身?

编辑:具体来说,我在 Sheet1 B1:B100 中有一个单元格位置列表,在 Sheet 2 上有一个数组 (A1:Z26) 引用这些位置。在条件格式中使用以下论坛,

=MATCH(CELL("address",A1),Sheet2!$B:$B,0)

然后,我希望单元格(如果为 TRUE)更改(可能通过 INDEX/MATCH),以在同一行的不同列 A 中显示工作表 1 上的值。

例如,如果工作表 1,A1=John Smith B1=$Z$26,那么工作表 2 的 Z26 将 =“John Smith”。

标签: excelvbaconditional-formatting

解决方案


I was able to do it with the following custom function entered in every cell in the range Sheet2!$A$1:$Z$26, like so: =Findvalue(Sheet1!$B$1:$B$26), with the below data entered into sheet1

content of sheet 1

Function FindValue(ByVal searchRange As Range)

    Dim formulaInCell As Range
    Dim cll As Range

    Set formulaInCell = Application.Caller

    Set cll = searchRange.Find(What:=formulaInCell.Address, lookat:=xlWhole)

    If cll Is Nothing Then

        FindValue = ""

    Else

        Set cll = cll.Offset(0, -1)
        FindValue = cll.Value

    End If

End Function

推荐阅读