Power Query Problems

Convert Consecutive Excel PIN Codes into From and To Ranges

Bushra ParveenBushra Parveen Nov 3, 2026 868 views

Question details

The user needs to group a large dataset of PIN codes into consecutive 'From' and 'To' range columns while preserving related row information such as dealer, branch, and state.

Convert Consecutive Excel PIN Codes into From and To Ranges
Product
Microsoft Excel
Device & OS
not provided
Scenario
Organizing and consolidating extensive geographical or delivery routing data by converting lists of sequential PIN/zip codes into grouped range brackets.
Observed behavior
Individual PIN codes are currently listed row by row and need to be transformed so that consecutive sequences are summarized into start and end points, with isolated single PINs duplicated in both columns.
Before you start

Make sure your data is correctly sorted numerically by the PIN code column and grouped by any relevant branch or dealer columns before attempting to transform the ranges.

Solution 1Recommended

Use Power Query to Group Consecutive PINs

Power Query provides a reliable, formula-free method to group sequential numbers by creating a custom grouping index.

This method is natively supported in Excel 365, Excel 2016, and Excel 2019. For Excel 2010 or 2013, the Power Query add-in must be downloaded and installed.

1
Load data into Power Query

Select any cell in your data list, go to the 'Data' tab on the ribbon, and click 'From Table/Range' to open the Power Query Editor.

2
Sort the dataset

Click the drop-down arrow on your descriptive columns (like dealer or branch) to sort them, then sort the PIN code column in Ascending order.

3
Add an Index and Grouping column

Go to the 'Add Column' tab, click 'Index Column' (starting from 1). Then, add a Custom Column that subtracts the Index value from the PIN Code. This creates a unique identifier for each block of consecutive numbers.

4
Group the data

Select your descriptive columns (dealer, state, etc.) along with the new Custom Column. Right-click and choose 'Group By'. Create two new aggregations: 'From' (using the Minimum of the PIN column) and 'To' (using the Maximum of the PIN column).

5
Load the transformed data

Remove any temporary index or custom identifier columns, then click 'Home' > 'Close & Load' to export the grouped ranges back into a new Excel sheet.

Use Power Query to Group Consecutive PINs
Single PINs Handled Automatically: Using the Min and Max aggregation naturally copies a single, non-consecutive PIN code into both the 'From' and 'To' columns without requiring extra logic.
Manage Data efficiently with WPS Office

Use WPS Spreadsheet to Organize PIN Code Ranges

WPS Spreadsheet provides powerful data processing tools. You can easily sort, filter, and use robust array formulas or VBA macros to group consecutive PIN codes without complex add-ins.

  1. 1. Open your dataset in WPS Spreadsheet: Launch WPS Office, open Spreadsheet, and load your original Excel file containing the PIN codes.
  2. 2. Sort and Add Helper Columns: Sort your data by branch and then by PIN. Use an IF formula (e.g., =IF(B2=B1+1, A1, B2)) to assign group IDs to consecutive sequences.
  3. 3. Extract Minimum and Maximum Values: Use the built-in PivotTable feature to group your data by the new ID, setting the PIN field to display both MIN (From) and MAX (To) values.
Seamless format compatibility with Microsoft Excel (.xlsx, .xls, .xlsm).Full support for VBA macros to automate complex grouping tasks.Lightweight architecture handles large datasets smoothly and efficiently.Completely free to use with a highly intuitive interface.
microsoft office alternative - wps office

Frequently Asked Questions

Can I group consecutive numbers in Excel without Power Query?

Yes, you can use a combination of helper columns with IF formulas to identify gaps between numbers, and then use Pivot Tables or MINIFS/MAXIFS functions to extract the start and end of each range. Alternatively, VBA macros can automate this.

What happens if a PIN code does not have consecutive numbers next to it?

When calculating the minimum and maximum values for that specific grouping block, the single PIN code acts as both the start and end point. It will correctly be copied into both the 'From' and 'To' columns automatically.

Will grouping the PIN codes delete my other data columns like dealer and branch?

No. When using Power Query or Pivot Tables, you specify the descriptive columns (dealer, branch, state) as your primary grouping levels. The ranges are calculated strictly within those groups, keeping all related data perfectly intact.