0

如果该行中的某个单元格包含任何文本,我有这个公式会为该行添加一个边框:

=$C5<>""

我想将公式更改为不仅查看 C 列,而且查看表中的整行(即 A:I),即如果该行中存在任何文本,则必须应用格式。

似乎无法正确处理。

4

2 回答 2

0

试试这个。我已经测试过了,它对我有用。您需要将“ Sheet1 ”名称更改为您的工作表名称。当前宏设置为第 100 行。检查i = 1 到 100的值

Sub FormatCells()
Dim Wks As Worksheet: Set Wks = Sheets("Sheet1")
Dim i As Integer
For i = 1 To 100 ' set the max no of Rows
LookupRange = Wks.Rows(i)
    If Application.WorksheetFunction.CountA(Wks.Rows(i)) <> 0 Then
        With Wks.Rows(i).Borders(xlDiagonalDown).LineStyle = xlNone
             Wks.Rows(i).Borders(xlDiagonalUp).LineStyle = xlNone
        End With
        With Wks.Rows(i).Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlMedium
        End With
        With Wks.Rows(i).Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlMedium
        End With
        With Wks.Rows(i).Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlMedium
        End With
        With Wks.Rows(i).Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlMedium
        End With
    End If
Next i
End Sub

希望这可以帮助。干杯!

于 2013-10-03T12:00:55.657 回答
0

只需使用此公式

=COUNTA($A5:$I5)>0

COUNTA计算非空白单元格,因此如果该范围内有任何文本 COUNTA 将 > 0 并触发条件格式

于 2013-10-07T00:20:50.967 回答