How to turn a series of hyphenated and un-hypenated numbers into a shortened hyphenated range?

freedom123

New Member
Joined
Aug 22, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Basically I have a bunch of numbers in a list. Each number/hypehnated number is in it's own row. Some are by themselves some are in hyphenated ranges.
I want to put them all together into one shortened hyphenated range if that makes any sense

So for example

001, 002-010, 010-055, 059, 061, 063-067 will become 001-055, 059, 061, 063-067 after everything.

Screenshot 2023-08-22 010301.png
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Free Let's get the ball rolling. Now this is my solution to your problem. It's probably not the best solution but we have to start somewhere. Usually this generates more questions than answers so let the discussion begin.

Book1
ABC
2001
3002-010
4010-055
5059001, 002-010, 010-055, 059, 061, 063-067
6061
7063-067
Data
Cell Formulas
RangeFormula
C5C5=CONCATENATE(A2,", ",A3,", ",A4,", ",A5,", ",A6,", ",A7)
 
Upvote 0
Free Let's get the ball rolling. Now this is my solution to your problem. It's probably not the best solution but we have to start somewhere. Usually this generates more questions than answers so let the discussion begin.

Book1
ABC
2001
3002-010
4010-055
5059001, 002-010, 010-055, 059, 061, 063-067
6061
7063-067
Data
Cell Formulas
RangeFormula
C5C5=CONCATENATE(A2,", ",A3,", ",A4,", ",A5,", ",A6,", ",A7)
Hello, thank you.
I've actually been using a slightly similar formula, the TEXTJOIN() formula and manually shortening the TEXTJOIN() string.
Hopefully someone has some insight on this
 
Upvote 0
Please try this one and let me know if there is any bug .
shortened hyphenated range.xlsx
ABC
1001
2002-010结果
3011-055001-055,059,061,063-067,073-075,099,101-103
4059
5061
6063-067
7073-075
8099
9101
10102
11103
Sheet1
Cell Formulas
RangeFormula
C3C3=REDUCE(,A1:A11,LAMBDA(x,y,IF(LEFT(y,3)-RIGHT(x,3)=1,IF(LEFT(RIGHT(x,4))="-",LEFT(x,LEN(x)-4),x)&"-"&RIGHT(y,3),x&","&y)))
 
Upvote 0
So Free, If I am understanding correctly, you are using the below example and function. So what is the problem. Does column A have lots of data and takes a long time to set up? Is the answer not in the form you want? Let us know.

Book1
ABC
2001
3002-010
4010-055001, 002-010, 010-055, 059, 061, 063-067
5059
6061
7063-067
Sheet1 (3)
Cell Formulas
RangeFormula
C4C4=TEXTJOIN(", ",TRUE,A2,A3,A4,A5,A6,A7)
 
Upvote 0
Hi

freedom123


The data you showed as expected is not consistent with the picture

So Free, If I am understanding correctly, you are using the below example and function. So what is the problem. Does column A have lots of data and takes a long time to set up? Is the answer not in the form you want? Let us know.

Book1
ABC
2001
3002-010
4010-055001, 002-010, 010-055, 059, 061, 063-067
5059
6061
7063-067
Sheet1 (3)
Cell Formulas
RangeFormula
C4C4=TEXTJOIN(", ",TRUE,A2,A3,A4,A5,A6,A7)
I believe the goal is to combine consecutive ranges into a single range so long as there is not a skipped value between them.

IE: 001, 002-010, 010-055 can be represented as 001-055 because there is no skipped value between each range. If rows 6 and 7 had the values of 062 and 063-067, you could represent that in a single range as 062-067, but because row 6 has the value 061, they will be two separate ranges because it skips 062 between them.

That being said, I don't really have an idea how to solve the problem, just thought I could help clarify what is being asked.

Edit: However, it looks like shaowu459 has a solution.
 
Upvote 0
dreid yes I see that now. And it does look like shaowu has the solution. Now we just need free to weigh in and tell us.
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,263
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top