VBA Make a Merged Title by the number of populated cells in the next row down

Dave01

Board Regular
Joined
Nov 30, 2018
Messages
116
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi,

I havnt got anything to share as Im not sure how to start this, what I am trying to do is produce a centered title across a pivot table. The amount of merged cells for the title will depend on how many of the below cells are populated.

so in the picture C5 is my title, but as the Pivot will expand and shrink based on what is populated then the the title in C5 needs to expand and shrink with it, basically trying to add a title above the pivot table.

Im thinking

activates C5
colour no fill
unmerge

Count rows C6 to end of populated rows ( so from company Code to Grand total) total 11 cells in the row
Merge C5 by 11 rows. to make the title accross the pivot table

Any ideas please ?

thanks

Dave
 

Attachments

  • 1.JPG
    1.JPG
    41.2 KB · Views: 7

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
VBA Code:
    Rows(5).Clear
    With Range("C5").Resize(1, ActiveSheet.PivotTables(1).TableRange1.Columns.Count)
        .MergeCells = True
        .HorizontalAlignment = xlHAlignCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .Interior.ColorIndex = 44
        .Value = "This is my header"
    End With
 
Upvote 0
sorry for the delay

perfect thank you

David
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top