Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is it possible to dynamically apply "merge & Center" based on values or through "Conditional Formatting"?

I made it possible to add colors but I want to do more advanced thing with Excel do dynamic "merge & Center" something like the image below enter image description here

all the values are dynamic!

share|improve this question

Not using merge cells (which is horrible anyway), but for your case you could far better anyway. This will take a bit of setting up but gives exactly the effect you want.

Have a column (A) for month but simply repeat the date in it (A2: =C2). Don't calculate the month here, we want to retain the date so you can simply format to show month only later.

For column B weeks, use WEEKNUM(C2,2) to calculate ISO weeks (Monday = day 1) Copy these formulas down A and B as far as needed.

Format both of these columns to use a custom number format of ;;; this means all those values completely disappear, and we will bring them back selectively using conditional formatting.

For column A you need to see the month name if:

  1. this is the first row, and after the 15th of the month
  2. this is the last row, and before the 15th of the month
  3. otherwise (normally) show the month name against the 15th as roughly the middle of the month. So, you need to apply a condition to cells A2:A999 (or whatever the length of your column is) as follows:


Note the first condition checks if the current row date = "whatever the label of your date column is" rather than hardcoding as ="Date" or somesuch.

Set the format for these to use a custom number format of "MMM" (three letter months), or whatever is your preference.

For weeknumbers, these should show similarly on days at the top or bottom of the list, or normally on Thursdays (visually this is mid-week if you have Mon=1, but if you want them against Wednesdays instead as "mid-week" day, use 3 instead of 4 in formula below). Apply conditional format by formula:


And use a suitable number format (0 or 00 probably best)

To alternate background colours, use the same sort of approach - colour them all then conditionally colour some back again. So colour all the cells with a light background fill then use conditional formats to colour them darker (or vice versa) based on the value of these columns is "even" ie formula for weeks is something like:


or in the case of months include the MONTH calculation ie condition uses


Do this separately for months and weeks. It should now look something like the below image.

Hope this helps!

Using conditional formatting to show centred weeks and months

share|improve this answer

Short answer to the direct question is ... "No"

Conditional formating can apply formating to individual or already merged cells, but it cannot cause cells to be merged.

The only way to achieve what you are asking for on the raw data would be through a vba macro, either based on a sheet or workbook event (complex and probably not worth the trouble) or user triggerd

share|improve this answer

You can't do merge and center with conditional formatting. Pivot tables will achieve this effect. You can use calculated fields to generate the year and week fields on your dynamic data.

share|improve this answer

ISO weeks cannot directly be calculated in Excel (it is not the same as 'week starts on Monday').

Use the following formula:


Source: Week numbers in Excel

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .