Excel user defined function if cell is highlighted then

房东的猫 提交于 2019-12-24 13:58:23

问题


I have created a user defined function to determine whether cells are highlighted a particular color, and it works in some situations, but not the one I need; Basically it works when that cell is permanently highlighted that color but I am basing it on conditional formatting and the function doesn't work if the cell is that color due to conditional formatting.

    Public Function Active(Rng As Range) As Boolean
        If Rng.Interior.Color = RGB(217, 151, 149) _
            Then Active = True
    End Function

Any help as to why would be much appreciated.


回答1:


For simple Conditional Formatting (NONE-Color scaling type), you can refer to @brettdj and @Chuff 's external reference http://www.xldynamic.com/source/xld.CFConditions.html#specific

How do I find the fill colour value of a conditionally formatted cell in Excel 2007 using vba?

For color scaling Conditional formatting, I have tried pasteSpecial but it's not working.

The only workable solution for me is to copy the range into MS Word, and then copy the range back into EXCEL. This will remove the conditional formatting. Then you can get the background color as Cells(X,Y).interior.color

Or else you need to implement the color scaling type of conditional formatting yourself.




回答2:


Can you perhaps use the same criteria in your udf as used by the conditional formatting? Instead of checking for color, check the factors the conditional format checks for.



来源:https://stackoverflow.com/questions/13913004/excel-user-defined-function-if-cell-is-highlighted-then

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!