English 中文(简体)
设法在纸面纸面表上向一栏外地负责人提供彩色,然后打字。
原标题:Trying to give color to column field headers in pivot table with vba
  • 时间:2024-03-30 01:46:29
  •  标签:
  • excel
  • vba

试图在我的纸浆桌上给各栏的字体贴上白色。

“entergraph

I tried doing it like this:

  Format column field headers
For Each pvtField In pvtTable.ColumnFields
    With pvtField.LabelRange
        .Interior.Color = RGB(0, 0, 77)   Dark Blue
        .Font.Color = RGB(255, 255, 255)   White
        .Font.Bold = True
    End With
Next pvtField

But it didnt work, then I tried a more manual way, like this:

  Column headers are the fith row in TableRange2
Set headerRow = pvtTable.TableRange2.Rows(5)
With headerRow
    .Interior.Color = RGB(0, 0, 77)   Dark Blue
    .Font.Color = RGB(255, 255, 255)   White
     .Font.ColorIndex = 2   White   White
    .Font.Bold = True
End With

第2条 蓝色正确,但不是真白。

Any ideas?

问题回答
  • 利用<代码>TableRange2.Rows(5)查找负责人并不可靠。 这取决于纸面上有多少页田。

  • TableRange1系指含有整个可用范围,但其中不包括页数。

Microsoft documentation:

PivotTable.TableRange1 property (Excel)

Microsoft documentation:

Application。 工会方法(Excel)

Sub HighLightPvtHeader()
    Dim pvtTable As PivotTable, pvtField As PivotField
    Dim headerRow As Range
    Set pvtTable = Sheet1.PivotTables(1)
    With pvtTable.TableRange1.Rows(2)
        Set headerRow = .Resize(, .Columns.Count - 1).Offset(, 1)   modify as needed
    End With
    For Each pvtField In pvtTable.ColumnFields
        Set headerRow = Union(headerRow, pvtField.LabelRange)
    Next pvtField
    With headerRow
        .Interior.Color = RGB(0, 0, 77)   Dark Blue
        .Font.Color = vbWhite
        .Font.Bold = True
    End With
End Sub

“enterography





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签