在Excel中使用图标集和相对引用的条件格式

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

为了澄清,我想要做的是应用基于当前date和项目的目标date之间的关系完成的图标集。

– 只要目标date至less有一周或单元格读数为100%,单元格将显示复选标记。

– 如果目标date和当前date之间less于7天,则会显示感叹号。

– 如果当前date与目标date相同,并且单元格的值不是100%,则显示x。

被用作条件的代码是:

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

我想要的是相当于:

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

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

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

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

如果其他人遇到这个问题,您可以使用相对引用…至less这比手动设置每个单元格或列的规则更快。 首先做一个单元格(你只能select一个单元格),然后使用INDIRECT来引用这个值,例如,在条件规则里相对引用一个列值(或者如果需要,可以使用行等等):

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

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

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

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

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

主要的代码块在下面,但是你可以在我的网站上看到更多的细节http://davidoverton.com/blogs/doverton/archive/2017/02/04/how-to-use-office-conditional-formatting-对放入的图标集-比较-一个范围-细胞- -或相对引用,作为办公通话,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 

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

  1. 为第一行或第一列设置格式规则。 请确保将额外的$退出。 (你已经做了很多)
  2. 复制它。
  3. select下一行/列
  4. 转到select性粘贴 – > 粘贴格式

那样有用吗?