带有图标集的条件格式和excel中的相对引用

时间:2013-05-31 18:08:20

标签: excel excel-2007 excel-formula

我想知道是否有任何方法可以在excel中使用相对引用图标集。理想情况下,我想锁定行,同时允许列在复制并粘贴到工作表上时更改(例如D $ 3)。 Excel告诉我,我无法使用图标集进行相对引用。

为了澄清,我要做的是根据当前日期和要完成的项目的目标日期之间的关系应用一个图标集。

- 只要在目标日期之前至少有一周或者单元格读数为100%,该单元格将显示一个复选标记。

- 如果目标日期和当前日期之间的时间少于7天,则会显示一个感叹号。

- 当前日与目标日期相同且单元格值不是100%时显示x

用作条件的代码是:

=OR(TODAY()+7-$D$14,$D$12=100)

我想要的是相当于:

=OR(TODAY()+7-D$14,D$12=100)

我只是不知道如何去做 提前谢谢

下面是格式规则窗口: Formatting rule

4 个答案:

答案 0 :(得分:0)

如果没有%出现在所有单元格中,我可以看到满足您要求的唯一方法是在这些单元格中输入100以显示刻度和100%,然后格式化这些特定单元格#,###“%”

答案 1 :(得分:0)

如果其他人遇到此问题,您可以使用相对引用...至少这比手动为每个单元格或列设置规则要快。首先进行一个单元格(您只能选择一个单元格),并使用INDIRECT来引用该值,例如相对引用条件规则内的列值(或者如果需要可以使用行等等):

=INDIRECT("R14C" & COLUMN(), FALSE)

或要转换impactblu的公式,你可以这样输入:

=OR(TODAY()+7-INDIRECT("R14C" & COLUMN(), FALSE),INDIRECT("R12C" & COLUMN(), FALSE)=100)

然后只需复制单元格,然后将“格式化”粘贴到需要应用图标集或颜色比例的其他单元格中。如果您相对引用行和列,则必须一次粘贴一个单元格。如果在上面提到的示例公式中我只提到了一个列,但是行是绝对的,那么你可以一次粘贴一个整列。
还有其他方法来加快这个速度,但是你得到了它的要点。

答案 2 :(得分:0)

最后,我编写了一个通用宏来启用两个数据集之间的图标比较,并将整批应用到一个范围。

主要代码块如下,但您可以在我的网站http://davidoverton.com/blogs/doverton/archive/2017/02/04/how-to-use-office-conditional-formatting-to-put-in-icon-sets-comparing-a-range-of-cells-or-relative-references-as-office-calls-it.aspx

上查看更多详细信息
Sub CompareIcons()      
   'In this example it starts in cell Q202 and compares to the cell Q210 and does this for 5 rows and 9 columns.  The icons used at xl3Arrows and removes all other conditional formatting on the cells impacted.
    Call GenericIconComparison(Range("q202"), Range("q210"), 5, 9, xl3Arrows, False, False, True)   

'In this example it compares the range from Q202:Y206 to the cells starting in Q210, so in effect the same as the one above
    Call GenericIconComparison(Range("q202:Y206"), Range("q210"), 0, 0, xl3Arrows, False, False, True)  
 

'In this example it does the same as the others, except higher values get a downward arrow and lover values get a higher value
    Call GenericIconComparison(Range("q210"), Range("q202"), 5, 9, xl3Arrows, True, False, True) 
 
End Sub 

Below is the VBA code to implement everything I’ve spoken about.  It does what is says on the tin.
Sub GenericIconComparison(IconsTopleft As Range, CompareTopLeft As Range, Rows As Integer, Cols As Integer, Icons As XlIconSet, ReverseOrder As Boolean, ShowIconsOnly As Boolean, RemoveOtherCondFormatting As Boolean) 
' 
' Icon Comparisons for ranges 
' 
    
    'get column top left for from and too ranges 
    from_col_number = IconsTopleft.Column 
    to_col_number = CompareTopLeft.Column 
    'If a range is given, use that over rows and cols parameters 
    If IconsTopleft.Columns.Count > 1 Then Cols = IconsTopleft.Columns.Count 
    If IconsTopleft.Rows.Count > 1 Then Rows = IconsTopleft.Rows.Count 
    For i = 1 To Cols 
        'get Column letter for from cell 
        from_col = from_col_number + i - 1 
        If from_col > 26 Then 
            col = Chr(64 + Int((from_col - 1) / 26)) + Chr(64 + from_col - Int((from_col - 1) / 26) * 26) 
        Else 
            col = Chr(64 + from_col) 
        End If 
        'get Column letter for comparison cell 
        to_col = to_col_number + i - 1 
        If to_col > 26 Then 
            ToCol = Chr(64 + Int((to_col - 1) / 26)) + Chr(64 + to_col - Int((to_col - 1) / 26) * 26) 
        Else 
            ToCol = Chr(64 + to_col) 
        End If 
        
        'create the rules 
        For j = 1 To Rows 
            'select the cell 
            Range(col + Trim(j + IconsTopleft.Row - 1)).Select 
            'clear other formatting if desired 
            If RemoveOtherCondFormatting = True Then Selection.FormatConditions.Delete 
            'add the rule to compare to other cell 
            Selection.FormatConditions.AddIconSetCondition 
            Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority 
            With Selection.FormatConditions(1) 
                .ReverseOrder = ReverseOrder 
                .ShowIconOnly = ShowIconsOnly 
                .IconSet = ActiveWorkbook.IconSets(Icons) 
            End With 
            With Selection.FormatConditions(1).IconCriteria(2) 
                .Type = xlConditionValueNumber 
                .Value = "=$" + ToCol + "$" + Trim(j + CompareTopLeft.Row - 1) 
                .Operator = 7 
            End With 
            With Selection.FormatConditions(1).IconCriteria(3) 
                .Type = xlConditionValueNumber 
                .Value = "=$" + ToCol + "$" + Trim(j + CompareTopLeft.Row - 1) 
                .Operator = 5 
            End With 
        Next 
    Next 
End Sub 

答案 3 :(得分:-1)

我对图标集的工作量不大,但这听起来像是一般的条件格式问题。尝试:

  1. 仅针对第一行或第一列设置格式规则。请务必留出额外的$。 (你已经完成了这个)
  2. 复制它。
  3. 选择下一行/列
  4. 转到选择性粘贴 - > 粘贴格式
  5. 这有用吗?