简体   繁体   English

非空单元格上的条件格式-Excel VBA 2010

[英]Conditional formatting on non-empty cells - Excel VBA 2010

I have 3 correlation matrices: 我有3个相关矩阵:

Input Correlation: 输入相关性:

                 Acc & Health     AE     Avemco Aviation      Bail
Acc & Health         1           0.15        0.15            0.15
AE                  0.15          1          0.15            0.25
Avemco Aviation     0.15         0.15         1              0.15
Bail                0.15         0.25        0.15              1

Output Correlation: 输出相关:

                Acc & Health      AE     Avemco Aviation      Bail
Acc & Health         1          
AE                 0.158          1     
Avemco Aviation    0.139        0.158            1  
Bail               0.177        0.258          0.130           1

Comparison Correlation (absolute value of Input - Output Correlation tables): 比较相关性(输入-输出相关性表的绝对值):

                Acc & Health      AE     Avemco Aviation      Bail
Acc & Health       0.000             
AE                 0.008        0.000       
Avemco Aviation    0.011        0.008          0.000    
Bail               0.027        0.008          0.020         0.000

I'm applying conditional formatting to the Comparison Correlation table if the Input Correlation table values are greater than 0.2 AND another mathematical condition AND if the cells in the Comparison Correlation table are NOT blank: 如果输入相关性表的值大于0.2和另一个数学条件,并且比较相关性表中的单元格不是空白,则我将条件格式应用于比较相关性表:

HOWEVER, I'm still getting formatting in blank cells like E3 (AE and Bail) since the input value is greater than 0.2. 但是,由于输入值大于0.2,所以我仍然在E3之类的空白单元格(AE和Bail)中进行格式化。 How do I fix this so no formatting is done on blank cells?? 如何解决此问题,以便不对空白单元格进行格式化?

Part of my code in VBA: 我在VBA中的部分代码:

.Range(.Cells(5, 2), .Cells(LastRowAgg, LastColumnAgg)).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
                "=AND((('Input Correlation'!B5:AT49-'Aggregate Loss Correlation'!B5:AT49)/'Input Correlation'!B5:AT49)>=(1/3),'Input Correlation'!B5:AT49>=0.2,B5:AT49<>"" "")"
            Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
            With Selection.FormatConditions(1).Interior
                .PatternColorIndex = xlAutomatic
                .Color = 255
                .TintAndShade = 0
            End With
        Selection.FormatConditions(1).StopIfTrue = False

Any help will be appreciated! 任何帮助将不胜感激!

I suggest you use an if statement together with the isblank() function: 我建议您将if语句与isblank()函数一起使用:

... Formula1:="=IF(isblank(a32);;and(a32<=a$19;a32>a$18))"

If isblank is True , do nothing else evaluate formula (and(a32<= ... ) 如果isblankTrue ,则不执行任何计算公式(and(a32<= ... )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM