How to ungroup many columns on a worksheet

I currently have a worksheet with several grouped columns.

I wanted to remove ALL grouped columns and my initial following code did not work:
cells.UngroupColumns(cells.MinColumn, cells.MaxDataColumn + 1);

I changed the code to this and it did work:
cells.UngroupColumns(cells.MinColumn, cells.MaxColumn + 1);


Hi,


Good to know that your have sorted it out by yourself.

Moreover, for your information, MaxColumn would give the farthest column index which contains data or formattings where as MaxDataColumn would give your the farthest column index which contain data. In short, if you got some grouped cells with only formattings applied and without any data/values, you should use MaxColumn attribute instead.

Thank you.