Split by text and add weeks

tobermory

New Member
Joined
Jun 4, 2012
Messages
46
Hello there,

I have a column that indicates weeks where a class is taking place. However, instead of listing each individual week number, it groups them together. For instance, 20-28 is weeks 20,21,22,23,24,25,26,27,28.

The column has instances of multiple groupings, separated by comma. I include a screenshot below. I'm looking to convert the groupings into individual weeks.

1663676015714.png


Column N is my own manual working, where I've manually converted the weeks into the output I am looking for. Would there be a combination of formulas, beyond my knowledge, that could take the manual work out of this process?

Note - Some rows are just individual week numbers and do not contain either a comma or dash.

20-28, 33-35
20-24, 26-28, 33-34

Thanks in advance!

Tobermory
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Here a VBA solution

VBA Code:
Sub jec()
 Dim ar, it, sp, x, j As Long, jj As Long
 ar = Range("A1", Range("A" & Rows.Count).End(xlUp))
 
 For j = 1 To UBound(ar)
   For Each it In Split(ar(j, 1), ",")
     sp = Split(it, "-")
     If UBound(sp) = 0 Then Exit For
     For jj = sp(0) To sp(1)
        x = x & IIf(x = "", "", ",") & jj
     Next
     ar(j, 1) = x
   Next
   x = ""
 Next

 Range("A1", Range("A" & Rows.Count).End(xlUp)) = ar
End Sub
 
Upvote 0
Upvote 0
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,589
Members
449,174
Latest member
chandan4057

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