I'm trying to use the -putexcel- command to create tables with a header at the top. I found the -tab2xl- program on the Stata website and that suits what I need for this project nicely. However, when I run the code below and then open I get an error telling me that there is an error (which Excel is kind enough to help me recover from) and then further that the error is related to the merge command below. Ideally I would like the grey box to extend over the top of the table and have the variable label displayed nicely. However, when I run the code, it still seems to only be the A column cell, rather than in the merged A:D cell. I'm using Excel 2019 and Stata 16.

Array


Array

Code:
*net install http://www.stata.com/users/kcrow/tab2xl, replace
sysuse auto, clear
replace turn = round(turn,5)

local row = 2
local empty = `row' + 1
putexcel set "AutoData.xlsx", modify sheet(Tabs)
putexcel describe
foreach var of varlist rep78 headroom turn {
    quietly: tab2xl `var' foreign using "AutoData.xlsx", row(`row') col(1) sheet(Tabs)
    putexcel describe
    quietly: tab `var' foreign, m
    local Varlab : variable label `var'
    display in red "Varlab: `Varlab'"
    quietly: putexcel B`row'="" 
    quietly: putexcel (A`row':D`row'), merge 
    quietly: putexcel (A`row'), hcenter border(all) fpattern(solid, gray)
    quietly: putexcel A`row'="`Varlab'", font(Calibri, 12, white)
    quietly: putexcel A`empty'="" 
    
    local row = `row' + `r(r)' + 5
    local empty = `row' + 1
}
putexcel save
Array