Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:26:31+00:00 2026-06-02T18:26:31+00:00

How do i group columns using Excel interop? if i record a macro (usually

  • 0

How do i group columns using Excel interop?

if i record a macro (usually a good way to get started) i get this code:

Columns("I:M").Select
Selection.Columns.Group

unfortunately this doesn’t work due to several problems, at least in C++. First of all, Application.Selection returns a normal Range, then Range.Columns is another Range. And Range.Group is this method:

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.group%28v=office.11%29.aspx

This method only works in connection with pivot tables.

So how do i create a column group using Excel interop?

Even if i manage to create a group, how can i shrink/expand it? By that i mean clicking on the + to show the content of the group, or rather the other way around, “click” on the minus to hide the group. If i do that while recording a macro, it is not reflected in the macro at all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:26:32+00:00Added an answer on June 2, 2026 at 6:26 pm

    Despite the fact that the Range.Group() documentation appears to relate to pivot tables, if you extract the columns using Range.Columns, and then apply the .Group() method to that range, it will have the desired effect. In C#:

    Range range = sheet.get_Range("c1","e1");
    range.Columns.Group();
    

    Edit: The complete example, again in C# (apologies, it’s the example I have handy):

    Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
    app.Visible = true;
    app.Workbooks.Add();
    Worksheet sheet = app.Workbooks[1].Sheets[1];
    Range range = sheet.get_Range("c1","e1");
    range.Columns.Group();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code: (from this question: How to get the last record
How can I group by multiple columns using linq projection? Something like this: var
Is there a way to group data into columns using a data bound control
Is there a way to GROUP BY using one column, but a set of
When I run a query using group by ... with rollup : select a,
I'm trying to do a group by using Zend framework. Here's my code: $table
I am using SQL Server and I have to group by a few columns
I am using a group by clause in my query. I want to get
How can I group by with multiple columns using lambda? I saw examples of
I have to display about 5 columns from 2 database tables using the Group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.