首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >excel中带图标集和相对引用的条件格式

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

Stack Overflow用户
提问于 2013-06-01 02:08:20
回答 4查看 19.1K关注 0票数 2

我想知道是否有任何方法可以在excel中使用相对引用和图标集。理想情况下,我希望锁定行,同时允许列在整个工作表中复制和粘贴时更改。D$3)。Excel告诉我我不能对图标集使用相对引用。

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

只要距离目标日期至少还有一周,或者如果单元格读数为100%,-The单元格就会显示复选标记。

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

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

用作条件的代码为:

代码语言:javascript
复制
=OR(TODAY()+7-$D$14,$D$12=100)

我想要的是等同于:

代码语言:javascript
复制
=OR(TODAY()+7-D$14,D$12=100)

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

下面是格式规则窗口:

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-06-01 04:28:32

如果所有单元格中都没有显示%,我能看到的满足您要求的唯一方法就是在这些单元格中输入100以显示勾号和100%,然后格式化这些特定的单元格#,###"%“。

票数 0
EN

Stack Overflow用户

发布于 2015-08-27 07:15:14

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

代码语言:javascript
复制
=INDIRECT("R14C" & COLUMN(), FALSE)

或者,要转换impactblu的公式,您可以像这样键入:

代码语言:javascript
复制
=OR(TODAY()+7-INDIRECT("R14C" & COLUMN(), FALSE),INDIRECT("R12C" & COLUMN(), FALSE)=100)

然后,只需复制单元格,并将格式粘贴到需要应用图标集或色标的其余单元格。如果同时相对引用行和列,则必须一次粘贴一个单元格。如果像我上面提到的这个例子中的公式,你只相对引用了一列,而行是绝对的,那么你可以一次粘贴一整列。

还有其他方法可以加速这一过程,但您已经掌握了其中的要点。

票数 0
EN

Stack Overflow用户

发布于 2017-02-05 17:20:03

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

主要代码块在下面,但您可以在我的网站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上看到更多详细信息

代码语言:javascript
复制
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 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16863317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档