我在Excel中有数据,如下所示,我想在这里显示两件事

时间:2014-04-28 11:44:02

标签: excel excel-formula conditional excel-2010 conditional-formatting

我在Excel中有数据,如下所示,我想在这里显示两件事。

1)如果尿素柱H = - 则B列应改变颜色。

2)如果MR +,VP应自动为 -

SLNo     SID      RV       TT       BSA      XLD      Lact.    Urea     TSI      Ind.     MR       VP       Cit.     Nitrate  Oxid     ONPG     PCR      SALM?    
                           S        B        H2S      G        R                                                                                                  
1        R.13     +        K        A        -        -        +        -        +        -        +        -        -                 -                          
2        5 TB     -        K        K        -        -        +        -        +        -        +        -        -                                            
3        7.3R     +        K        A        -        -        +        -        +        -        +        -        -                 +                          
4        11.1R    +        K        A        +        -        +        -        +        -        +        -        -                                            
5        15       +        K        A        -        -        +        -        +        -        +        -        -                                            
6        16.2RB   -        K                 +        -        +        -        +        -        D        -        -                                            
7        18.04    -        K        K        -        -        +        -        +        -        +        -        -                 -                          
8        18.1R             K        K        -        -        +        -        -        -        +        +        -                 -                          
9        20.2R             K        A        -        -        +        -        +        -        +        -        -                 +                          
10       20.3T    -        K        A        -        -        +        -        +        -        +        -        -                 +                          
11       R3D/ 28.1-        K                 +        -        +        -        +        -        -        --       -        +        +                          

ans 1:

我使用了条件格式化选项和= ISNUMBER(搜索(H5," - ")),这样可行,但尿素列中的问题是空白也突出显示颜色

ans 2:请建议

1 个答案:

答案 0 :(得分:0)

答案1:您的CF公式不正确。 Find_Text是第一个参数; within_text是第二个尝试:

=ISNUMBER(SEARCH("-",H2))

或更简单

=H2 = "-"

Ans 2 :您可以使用事件触发的宏。要输入此事件触发的宏,请右键单击工作表选项卡。 选择"查看代码"从右键单击下拉菜单中。 然后将下面的代码粘贴到打开的窗口中。

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rMR As Range, rVP As Range
    Dim C As Range
With Cells
    Set rMR = .Find(what:="MR", after:=[a1], LookIn:=xlValues, lookat:=xlWhole, _
                searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
    Set rVP = .Find(what:="VP")
End With
    If Not rMR Is Nothing And Not rVP Is Nothing Then
        Set rMR = Range(rMR, Cells(Rows.Count, rMR.Column).End(xlUp))
        Set rVP = rVP.Resize(rowsize:=rMR.Rows.Count)

Application.EnableEvents = False If Not Intersect(Target, rMR) Is Nothing Then For Each C In Intersect(Target, rMR) If C.Value = "+" Then rVP(C.Row).Value = "-" Next C End If If Not Intersect(Target, rVP) Is Nothing Then For Each C In Intersect(Target, rVP) If rMR(C.Row).Value = "+" Then C.Value = "-" Next C End If End If Application.EnableEvents = True End Sub