我有这个公式,如果该行中的某个单元格包含任何文本,则会为行添加边框:
=$C5<>""
我想将公式更改为不仅查看列C,而是查看表中的整行(即A:I),即如果该行中存在任何文本,则必须应用格式。
似乎无法做到正确。
答案 0 :(得分: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
希望这会有所帮助。干杯!
答案 1 :(得分:0)
只需使用此公式
=COUNTA($A5:$I5)>0
COUNTA
计算非空白单元格,因此如果该范围内有任何文本,则COUNTA将为&gt; 0并触发条件格式