The Problem (Q-score 17, ranked #20th of 303 in the Excel VBA archive)
The scenario as originally posted in 2013
I’d like to write a table like this:
----------------
| Long Cell |
----------------
| 1 | 2 |
----------------
How to write the cell Long Cell? Thanks.
I’ve tried to do it like this:
sheet.write(0, 0, 'Long Cell')
sheet.write(1, 0, 1)
sheet.write(1, 1, 2)
But it end up like:
--------------------
| Long Cell | |
--------------------
| 1 | 2 |
--------------------
Why community consensus is tight on this one
Across 303 Excel VBA entries in the archive, the accepted answer here holds elite answer (top 10 %%) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — elite answer (top 10 %%) (+35)
4-line Excel VBA pattern (copy-ready)
As far as I can tell, this isn’t documented – you have to read the source code to find it. There are two methods on the Worksheet class to do this, write_merge and merge. merge takes existing cells and merges them, while write_merge writes a label (just like write) and then does the same stuff merge does.
Both take the cells to merge as r1, r2, c1, c2, and accept an optional style parameter.
From your example, this would be the simplest call:
sheet.write_merge(0, 0, 0, 1, 'Long Cell')
sheet.write(1, 0, 1)
sheet.write(1, 1, 2)
To be more explicit about how the call works:
top_row = 0
bottom_row = 0
left_column = 0
right_column = 1
sheet.write_merge(top_row, bottom_row, left_column, right_column, 'Long Cell')
Alternatively, using merge:
sheet.write(top_row, left_column, 'Long Cell')
sheet.merge(top_row, bottom_row, left_column, right_column)
merge has some comments in the source pointing out potential problems:
# Problems: (1) style to be used should be existing style of # the top-left cell, not an arg. # (2) should ensure that any previous data value in # non-top-left cells is nobbled. # Note: if a cell is set by a data record then later # is referenced by a [MUL]BLANK record, Excel will blank # out the cell on the screen, but OOo & Gnu will not # blank it out. Need to do something better than writing # multiple records. In the meantime, avoid this method and use # write_merge() instead.
But it would be fine for a simple case like this.
Loop-performance notes specific to this pattern
The loop in the answer iterates in process. On a 2026 Office build, setting Application.ScreenUpdating = False and Application.Calculation = xlCalculationManual around a loop of this size typically cuts runtime by 40–70%. Re-enable both in the Exit handler.
When to Use It — classic (2013–2016)
Ranked #20th in its category — specialized fit
This pattern sits in the 90% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Excel VBA archive for a higher-consensus alternative.
What changed between 2013 and 2026
The answer is 13 years old. The Excel VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.