当连续3到10个最近的值超出限制时,Excel条件格式突出显示行

问题描述 投票:0回答:1

我创建了一个包含大约80,000个单元格的大型电子表格,其中包含一系列条件格式,突出显示不同的兴趣点。其中两种条件格式涉及导致文件减速的大型数组。我正在寻找一种方法来提高效率。

该表格从左到右,从1月1日到12月31日沿着顶部向下,向下读取各种项目,并在12月31日之后在最右边的各行中确定限制。日期排序可防止事先对数据进行排序。

下面是公式的初始根。然后将其复制以解决问题并导致问题。它查看非空单元格的未排序行,选取前X个值并将它们与Col $ NG中的限制进行比较。它忽略带有-5行引用的描述列,并提供0以避免因LARGE()的值不足而导致#NUM错误。

IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),1)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),1)))-5)>$NG2)

这是2个条件格式化公式中的第一个,旨在突出显示最近(最右边)值中的2个中的2个超过$ NG2中的限制时的行。

=IF(COUNT($F2:$NF2)<2,"",SUM(IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),1)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),1)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),2)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),2)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),3)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),3)))-5)>$NG2))>=2)

同样,根公式的复制10次,以捕获最高权限值中的3个超出限制。

=IF(COUNT($F2:$NF2)<2,"",SUM(IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),1)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),1)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),2)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),2)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),3)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),3)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),4)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),4)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),5)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),5)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),6)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),6)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),7)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),7)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),8)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),8)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),9)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),9)))-5)>$NG2),IF(ISERROR(INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),10)))-5)>$NG2),0,INDEX($F2:$NF2,SUMPRODUCT((LARGE(($F2:$NF2<>"")*COLUMN($F2:$NF2),10)))-5)>$NG2))>=3)

我考虑使用Do Until 2或3的xlToLeft VBA函数,但很难在索引匹配中复制变量列ID。

vba excel-2010 conditional-formatting worksheet-function
1个回答
0
投票

如果它对其他人有用,可作为参考:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim a, w, x, y, z As Integer
Dim b As Range

w = 0
x = Target.Row()
'Bypass limits column
y = Range("NG" & x).Column()
'Set column value while bypassing blanks
If Cells(x, y - 1) <> "" Then
    y = y - 1
Else
    y = Cells(x, y).End(xlToLeft).Column
End If
z = 0
a = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Set b = Range("F2:NF" & a)

If Not Target.Cells.Count > 1 Then
    If Not Application.Intersect(b, Range(Target.Address)) Is Nothing Then
        Do Until y = 5 Or z = 2 Or w >= 3
            If Cells(x, y) >= 0 Then
                If Cells(x, y) > Range("NG" & x) Then
                    z = z + 1
                End If
            End If
            w = w + 1
            If Cells(x, y - 1) <> "" Then
                y = y - 1
            Else
                y = Cells(x, y).End(xlToLeft).Column
            End If
        Loop
        If z < 2 And y > 5 Then
            Do Until y = 5 Or z = 3 Or w >= 10
                If Cells(x, y) >= 0 Then
                    If Cells(x, y) > Range("NG" & x) Then
                        z = z + 1
                    End If
                End If
                w = w + 1
                If Cells(x, y - 1) <> "" Then
                    y = y - 1
                Else
                    y = Cells(x, y).End(xlToLeft).Column
                End If
            Loop
        End If
        If z = 2 And w <= 3 Then
            With Range("A" & x, "E" & x).Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .Color = 12874308
                .TintAndShade = 0
                .PatternTintAndShade = 0
            End With
            With Range("A" & x, "E" & x).Font
                .Color = -2
                .TintAndShade = 0
            End With
            Range("A" & x, "E" & x).Font.Bold = True
        End If
        If z = 3 And w >= 3 Then
            With Range("A" & x, "E" & x).Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .Color = 7434613
                .TintAndShade = 0
                .PatternTintAndShade = 0
            End With
            With Range("A" & x, "E" & x).Font
                .Color = -13533715
                .TintAndShade = 0
            End With
            Range("A" & x, "E" & x).Font.Bold = True
        End If
        If z <= 2 And w > 3 Then
            If Range("A" & x).Font.Bold = True Then
                With Range("A" & x, "E" & x).Font
                    .ColorIndex = xlAutomatic
                    .TintAndShade = 0
                End With
                With Range("A" & x, "E" & x).Interior
                    .Pattern = xlNone
                    .TintAndShade = 0
                    .PatternTintAndShade = 0
                End With
                Range("A" & x, "E" & x).Font.Bold = False
            End If
        End If
    End If
End If
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.