如果满足条件,则将底部边框添加到一行中特定数量的列

Add bottom border to specific number of columns in a row if criteria is met

我有一个包含值组 1、2、3 等的列,以及包含其他详细信息的相邻列。我正在尝试编写一个宏,该宏将使用第一列来确定单元格中的值是否小于其下方的值,如果是,则为该单元格和同一行中接下来的 6 个单元格添加底部边框。

例如,如果 D2 包含“2”,D3 包含“3”,则 D2、E2、F2、G2、H2、I2、J2 都会收到一个底部边框。

我可以在 D2 下划线,但我不知道如何让它在接下来的 6 列下划线。

当前代码:

'line divider between wire groups
    For i = 2 To ws.Range("D" & ws.Rows.Count).End(xlUp).Row
        If ws.Cells(i, 4) < ws.Cells(i + 1, 4) Then
            With ws.Rows(i, 4)(i, 5)(i, 6)(i, 7).Borders(xlEdgeBottom)
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = 1
            End With
        End If
    Next i

不要为此使用 VBA,这是一种简单的条件格式。

Select 范围 D2:J2 并转到条件格式 --> 新规则

Select "Use a formula to determine ..." 然后输入这个公式:

=$D2=$D3-1

然后,转到 "Format" 并添加底部边框。