Excel Pivot Table: Cannot Group That Selection Error

Reasons for the ‘Cannot Group That Selection’ Error

  • Blank cells among numbers or dates
  • Texts with numbers or dates
  • Invalid format of numbers or dates

Excel Pivot Table: Cannot Group that Selection


How to Use Excel VBA to Detect Causes of the ‘Cannot Group That Selection’ Error

The sample dataset showcases a Product Order Record.

You want to group all Ship Dates, but the column contains different date formats and invalid dates.

Create a user-defined function to detect all cell types in the Ship Date column:

  • Press ALT + F11 to open the VBA Editor.
  • Go to Insert Module to create a new module.

  • Enter the following VBA code in the VBA Editor.
Public Function ValueType(c)

    Application.Volatile
    Select Case True
        Case IsEmpty(c): ValueType = "Blank"
        Case Application.IsText(c): ValueType = "Text"
        Case Application.IsLogical(c): ValueType = "Logical"
        Case Application.IsErr(c): ValueType = "Error"
        Case IsDate(c): ValueType = "Date"
        Case InStr(1, c.Text, ":") <> 0: ValueType = "Time"
        Case InStr(1, c.Text, "%") <> 0: ValueType = "Percentage"
        Case IsNumeric(c): ValueType = "Value"
    End Select

End Function

VBA to Detecte Causes of ‘Cannot Group that Selection’ Error

The code creates a user-defined function called ValueType. If you insert any cell address in the function, it will detect its cell type.

  • Create an additional column: Data Type.
  • Enter the following formula in G5.
=@ValueType(F5)
  • Press ENTER.

This formula returns the cell type of F5.

VBA to Detecte Causes of ‘Cannot Group that Selection’ Error

  • Drag down the Fill Handle to see the result in the rest of the cells.

There are 3 types of cell formats in the Ship Date column:

  • Date
  • Blank
  • Text

Convert all Blank and Text formats to Date.

Excel won’t show the error ‘Cannot group that selection’.


1. Invalid Data Format Results in ‘Cannot Group That Selection’ Error in Excel Pivot Table

In the Ship Date column, the red marked dates have an invalid date format.

Correcting Invalid Data to Fix ‘Cannot Group that Selection’ Error

  • Select a date.
  • Right-click it.
  • Go to Group.

Excel Pivot Table: Cannot Group that Selection

Excel shows the ‘Cannot group that selection’ error.

Excel Pivot Table: Cannot Group that Selection

There are invalid date formats.

Correct the invalid date formats. Use the format Month-Day-Year.

  • Group the dates.

No error occurs.

In the Grouping dialog box, select Months and click OK.

Excel Pivot Table: Cannot Group that Selection

Dates are grouped by Months.

Excel Pivot Table: Cannot Group that Selection


2. Blank Cells in the Dataset Cause the ‘Cannot Group That Selection’ Error in an Excel Pivot Table

In the Ship Date column, there are blank cells.

Filling Blank Cells to Fix ‘Cannot Group that Selection’ Error

  • Right-click a date in the Pivot Table.
  • Click Group.

Excel Pivot Table: Cannot Group that Selection

Excel shows the ‘Cannot group that selection’ error.

Excel Pivot Table: Cannot Group that Selection

  • Enter dates in the blank cells.

  • Group the dates.

No error occurs.

  • In the Grouping dialog box, select Months and click OK.

Excel Pivot Table: Cannot Group that Selection

Dates are grouped by Months.

Excel Pivot Table: Cannot Group that Selection

Read more: Pivot Table Custom Grouping


Practice Section

Practice here.


Download Practice Workbook

Download the Excel file.


 

Related Articles


<< Go Back to Group Pivot Table | Pivot Table in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mrinmoy Roy
Mrinmoy Roy

Mrinmoy Roy, a dedicated professional with a BSc in Electronics and Communication Engineering from Khulna University of Engineering & Technology, Bangladesh, brings over two years of expertise to the ExcelDemy project. As a prolific contributor, he has authored around 180 articles, showcasing his deep knowledge and passion for Microsoft Excel, Data Analysis, and VBA. His unwavering commitment to continuous learning, combined with versatile skills, renders him well-suited for roles in data management and spreadsheet solutions. He has interest... Read Full Bio

2 Comments
  1. I have this problem. But when I look at my data, everything is in the correct date format and there are no blanks.
    It’s a pivot table that has been in the spreadsheet for years and it only recently became unable to group. It was always grouped before.

    • Hello STEPH,
      Did you enter any newer data into your pivot table field? With newer or re-entry of data, you need to go to the PivotTable Fields window (at the right corner of the worksheet)-> unmark the corresponding field of your data (i.e. Ship Date for this article) -> right-click on the PivotTable and click Refresh-> again mark the corresponding field that you unmarked a little bit ago.
      Thanks and Regards

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo