Is there a better way to format table headers?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,532
Office Version
  1. 365
Platform
  1. Windows
I often have difficulty getting table headers to display the way I want them to. Here's an example of a table the way I would like it to look.

1711559920246.png


This is how it looks if I don't use one of the "solutions" discussed below. If I turn Wrap on, Excel breaks the headers on certain characters (space, minus, ???).

1711563489816.png


I have found 2 ways to get it to look like I want, but both have problems.
  1. Add extra spaces where I want the line to break. This is what I did in the example, above. See first minisheet below. This has two problems.
    1. If I change the column width, I have to adjust the number of extra spaces to match.
    2. Any formulas referencing these columns show the extra spaces.
  2. Add a manual line break (Alt+Enter). This is independent of the column width, so I don't have to adjust the header text, but the formulas are even crazier. They cannot be displayed on a single line in the formula bar. See second minisheet below.
Is there a better way?

This table uses the extra spaces. Notice the spaced out formulas (K6:N6).

Weighted Ratings Demo.xlsx
BCDEFGHIJKLMN
3Mean3.003.0015.008.00
4Std Dev1.581.587.911.58
5ABCDA ZB ZC ZD ZA 0-100B 0-100C 0-100D 0-100
6512510+1.26-1.26+1.26+1.261000100100
742209+0.63-0.63+0.63+0.6375257575
833158=0.00=0.00=0.00=0.0050505050
924107-0.63+0.63-0.63-0.6325752525
101556-1.26+1.26-1.26-1.26010000
Z Scores
Cell Formulas
RangeFormula
C3C3=AVERAGE(TblZs[A])
D3D3=AVERAGE(TblZs[B])
E3E3=AVERAGE(TblZs[C])
F3F3=AVERAGE(TblZs[D])
C4C4=STDEV.S(TblZs[A])
D4D4=STDEV.S(TblZs[B])
E4E4=STDEV.S(TblZs[C])
F4F4=STDEV.S(TblZs[D])
G6:G10G6=([@A]-C$3)/C$4
H6:H10H6=([@B]-D$3)/D$4
I6:I10I6=([@C]-E$3)/E$4
J6:J10J6=([@D]-F$3)/F$4
K6:K10K6=([@[A Z]]-MIN([A Z]))/(MAX([A Z])-MIN([A Z]))*100
L6:L10L6=([@[B Z]]-MIN([B Z]))/(MAX([B Z])-MIN([B Z]))*100
M6:M10M6=([@[C Z]]-MIN([C Z]))/(MAX([C Z])-MIN([C Z]))*100
N6:N10N6=([@[D Z]]-MIN([D Z]))/(MAX([D Z])-MIN([D Z]))*100


This table used the manual line break (Alt+Enter). Notice the multi-line formulas (K19:N19).

Weighted Ratings Demo.xlsx
CDEFGHIJKLMN
18ABCDA ZB ZC ZD ZA 0-100B 0-100C 0-100D 0-100
19512510+1.26-1.26+1.26+1.261000100100
2042209+0.63-0.63+0.63+0.6375257575
2133158=0.00=0.00=0.00=0.0050505050
2224107-0.63+0.63-0.63-0.6325752525
231556-1.26+1.26-1.26-1.26010000
Z Scores
Cell Formulas
RangeFormula
G19:G23G19=([@A]-C$3)/C$4
H19:H23H19=([@B]-D$3)/D$4
I19:I23I19=([@C]-E$3)/E$4
J19:J23J19=([@D]-F$3)/F$4
K19:K23K19=([@[A Z]]-MIN([A Z]))/(MAX([A Z])-MIN([A Z]))*100
L19:L23L19=([@[B Z]]-MIN([B Z]))/(MAX([B Z])-MIN([B Z]))*100
M19:M23M19=([@[C Z]]-MIN([C Z]))/(MAX([C Z])-MIN([C Z]))*100
N19:N23N19=([@[D Z]]-MIN([D Z]))/(MAX([D Z])-MIN([D Z]))*100
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
When you're setting up the headers for a ListObject, remember they've gotta be unique, and whatever names you pick will show up in your formulas. In my opinion, it's preferred to use a ListObject and all its benefits as if it was a database table that only a Form can touch, if you're going to use it for work and show then make sure you won't have a complex view. Using the "view" as a form for entering data is a common practice among Excel users, most times that works, but once you want to make fancy stuff within controlled constraints, it's best to separate view from data entry.

As for your choices, each has its good points and bad points, but since you're basically stuck dealing with the limitations of the ListObject, I suggest these:
1. Change your header design
2. Don't use a ListObject
3. Keep unique things in the ListObject and add a line above with the same format but make sure it's not a part of the ListObject.
 
Upvote 0
When you're setting up the headers for a ListObject, remember they've gotta be unique,
Of course

and whatever names you pick will show up in your formulas.
I think that was my main point.

In my opinion, it's preferred to use a ListObject and all its benefits as if it was a database table that only a Form can touch, if you're going to use it for work and show then make sure you won't have a complex view. Using the "view" as a form for entering data is a common practice among Excel users, most times that works, but once you want to make fancy stuff within controlled constraints, it's best to separate view from data entry.
Hmm... I hadn't considered a form. But I think that's more work than I want to go to for this project.

As for your choices, each has its good points and bad points, but since you're basically stuck dealing with the limitations of the ListObject, I suggest these:
1. Change your header design
I don't know what you mean by that. Can you give an example?

2. Don't use a ListObject
Do you mean don't use a table? That would take away a lot of the benefits of a table. This is a relatively minor annoyance, so if there is no solution, I'll just live with it, like I do so many minor, and not so minor, annoyances from the geniuses at M$FT.

3. Keep unique things in the ListObject and add a line above with the same format but make sure it's not a part of the ListObject.
Not sure I understand this one either. Examples?
 
Upvote 0
Never happens to me.
Here's what I mean. I have a table with 4 columns of data (A, B, C, & D) and then two sets of 4 columns with derivative data. I want each of the 12 columns to have the base data letters (A-D) at the top of the headers on a line by themselves.
  1. Table 1 has the table headers formatted the way Excel formats them. In columns F-I, everything is on one line. In columns J-M, Excel broke the headers after the "-". Pertty much unreadable.
  2. Table 2 has the table headers formatted the way I want them. In columns S-X, I accomplished this by adding spaces after the letters (A-D) until they were on a line by themselves. This is a bit of a trial and error process.
  3. In Table 3, I widened columns AF-AM. This can happen if the data expands. Excel reformatted the headers and they are all screwed up again. To get it back the way I want it, I have to go in and add more spaces.
1711671410736.png


Is that clearer?

Are you saying widening the columns does not have the effect shown above for you?

Here's the minisheet.

Table Headers.xlsx
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAM
3Table 1Table 2Table 3
4BCDEFGHIJKLMOPQRSTUVWXYXABACADAEAFAGAHAIAJAKALAM
5ABCDA ZB ZC ZD ZA 0-100B 0-100C 0-100D 0-100ABCDA ZB ZC ZD ZA 0-100B 0-100C 0-100D 0-100ABCDA ZB ZC ZD ZA 0-100B 0-100C 0-100D 0-100
6512510+1.26-1.26+1.26+1.261000100100512510+1.26-1.26+1.26+1.261000100100512510+1.26-1.26+1.26+1.261000100100
742209+0.63-0.63+0.63+0.637525757542209+0.63-0.63+0.63+0.637525757542209+0.63-0.63+0.63+0.6375257575
833158=0.00=0.00=0.00=0.005050505033158=0.00=0.00=0.00=0.005050505033158=0.00=0.00=0.00=0.0050505050
924107-0.63+0.63-0.63-0.632575252524107-0.63+0.63-0.63-0.632575252524107-0.63+0.63-0.63-0.6325752525
101556-1.26+1.26-1.26-1.260100001556-1.26+1.26-1.26-1.260100001556-1.26+1.26-1.26-1.26010000
Table Headers (2)
 
Upvote 0
Hmm... I hadn't considered a form. But I think that's more work than I want to go to for this project.
That's perfectly valid. If you think a form is overkill, then don't add any form.

I don't know what you mean by that. Can you give an example?
Not sure I understand this one either. Examples?

Yes, this is what you want it to look:
1711678637043.png

1. Notice how I'm using two rows for the headers. You can't do this with a ListObject, that's why the first row is not a part of the ListObject. It's just a simple row formatted to look like it. For that, I had to duplicate the ListObject design; then I applied the duplicated design to the ListObject; finally, I modified the header to remove its top border. Once I was done with the ListObject format, applying a simple shade of the same color to the first row (the one that is not part of the ListObject) gives the desired effect. If you do not remove the border, it looks like this:
1711679659096.png

2. For columns A-D in my example, Z is not actually Z, but ZZ1, ZZ2, etc. Why does it show just Z? I simply edited the first and the last character to be the same color as the background. Had I used Z1, Z2, etc., it would not have been aligned with the character above. The double Z is just for consistency, what other character can you use? that's your choice, I chose the extra Z here.
1711679823592.png

3. Instead of just 0-100, they will be 0-1001, 0-1002, etc. In the first picture, I simply painted the last character with the same color as the background, again, but it will be there in the formula. The added character does not make it look off-center, so I left it like that. There's an argument to be made about consistency there, but we're working within the limitations of the tool.

This is what I meant by changing your header design and adding a line above. The workarounds aren't pretty, but the ListObject does not let us caption the columns, they just have a name property, so, again, we're working with the limitations of the ListObject, this is what we have for the columns:
1711680394018.png

Notice we only have a Name property. No caption. There's a ListDataFormat node there, but there's nothing usable there either. DataBodyRange, Range and the others are unusable too.

That's why separating view from data entry form is important. But if you want to avoid using a form and do everything directly on the report, workarounds will have to be made. You have made a few, these are just others. Any workaround fixes one thing and messes up another. It's up to us to decide what annoys us less. 4

In this case, I suggest making a form, saving the data in a ListObject and showing in some sort of report or view. But you've stated your position about not wanting to spend any more time on this.
 
Upvote 0
Solution
That's perfectly valid. If you think a form is overkill, then don't add any form.
My thinking exactly.

Notice how I'm using two rows for the headers.
I actually did fool around with that a bit, but the hassle of keeping the columns aligned was more trouble than I wanted.

For columns A-D in my example, Z is not actually Z, but ZZ1, ZZ2, etc. Why does it show just Z? I simply edited the first and the last character to be the same color as the background.
I forgot that I also played around with this awhile ago, too. The problem with it was that the formulas didn't look like the headers, which is error prone.

That's why separating view from data entry form is important. But if you want to avoid using a form and do everything directly on the report, workarounds will have to be made. You have made a few, these are just others. Any workaround fixes one thing and messes up another. It's up to us to decide what annoys us less. 4

In this case, I suggest making a form, saving the data in a ListObject and showing in some sort of report or view. But you've stated your position about not wanting to spend any more time on this.
Hmmm... I may have to rethink using a form.

Thanks

PS: I am going to mark your post as the solution because I think it's as close to a solution as we are going to get. Cheers
 
Upvote 0
When I use Excel tables then I do not add extra spaces or insert line brakes in the headers. As you pointed the structured references get garbled up. "Clean" display of formulas is more important then "clean" display of headers.
I may set "wrap text" if the header text is to wide and adjust the column width and the row heigth.
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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