【发布时间】:2018-06-29 16:10:08
【问题描述】:
我在 sheet1 中有一些数据作为表格(名为 Table1),并且我正在根据名称更改某些标题的字体颜色,并且我只想在其字体颜色为黑色时隐藏标题,因此请保持橙色和白色不-隐藏。当我打开原始工作表时,列标题的字体颜色为白色。
现在当我运行我的代码时,没有错误,但我只看到带有橙色字体颜色标题的列,这是不正确的。出于某种原因,当我将数据转换为范围时,它可以工作,但我不想使用unlist 并为数据重新创建一个表。
Sub Data_Formatting()
Dim i, j, k As Long
Range(Range("A1"), Range("A1").End(xlToRight)).Interior.Color = RGB(79, 129, 189)
Last = Cells(1, Columns.Count).End(xlToLeft).Column
For i = Last To 1 Step -1
If (Cells(1, i).Value) = "System" Then
Cells(1, i).Font.Color = RGB(0, 0, 0)
End If
Next i
For j = Last To 1 Step -1
If (Cells(1, j).Value) = "AOB" Then
Cells(1, j).Font.Color = RGB(255, 153, 0)
End If
Next j
Range("A:D").Columns.AutoFit
Dim l As Long
Dim lColumn As Long
Dim ws As Worksheet: Set ws = ActiveSheet
'Last column
lColumn = ws.Cells(1, Columns.Count).End(xlToLeft).Column
For l = 1 To lColumn
If Cells(1, l).Font.Color = RGB(0, 0, 0) Then
Cells(1, l).EntireColumn.Hidden = True
Else
Cells(1, l).EntireColumn.Hidden = False
End If
Next
End Sub
【问题讨论】: