2

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

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

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

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

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

用作条件的代码是:

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

我想要的是相当于:

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

我只是不知道该怎么做 提前谢谢

下面是格式化规则窗口: 格式化规则

4

4 回答 4

0

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

于 2013-05-31T20:28:31.907 回答
0

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

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

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

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

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

于 2015-08-26T23:15:13.520 回答
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 
于 2017-02-05T09:20:03.353 回答
-1

我不太使用图标集,但这对我来说听起来像是一个一般的条件格式问题。尝试:

  1. 仅为第一行或第一列设置格式规则。确保留下多余$的部分。(你几乎已经这样做了)
  2. 复制它。
  3. 选择下一行/列
  4. 转到选择性粘贴- >粘贴格式

那样有用吗?

于 2013-05-31T18:44:43.840 回答