Split ranges(001-005) but keep the associated column

norriz

New Member
Joined
Aug 14, 2010
Messages
30
I have table with a range of numbers with the associated name(below), need to find a way to split ex:001-005 to 001 and table1, 002 and table1, 003 and table1. Can this be done in access or excel. Help needed urgently. Thank you
NumberName
001-005table1
006-010table2
I'd like my final data to look like this-
Number Name
001 Table1
002 Table1
 
That doesn't clarify what you're looking for as solution.
Is that long string of numbers in ONE cell and then you want them broken out into multiple rows?
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
sample.xlsx
ABCDEF
1RangeNumberRangeNumber
2001-9995same0015
3001-99960025
4301-303, 311, 39970035
5169-179, 195-196, 2548
6298, 308-3099
7307, 373-37410
8350-352, 354-359, 36211
9360-361, 363-364, 367-36812
10430-433, 437-438, 456-45813
11460-462, 469, 472-474, 478, 47914
12150-154, 156, 160-165, 260, 265, 43916
13304, 310, 312, 318-31917
14370-372, 384, 385, 421-42218
15375, 380-383, 386, 388, 723-72419
16242, 376-379, 407-409, 417-418, 425-42620
17620, 622, 628-631, 633-634, 636-63921
18003, 010-043, 045, 048, 050-067, 068-079, 085-089, 100-149, 167, 200-212, 214-241, 243-253, 255-259, 261-264, 266-268, 270-297, 299, 313-317, 320-342, 344, 346-347, 349, 365-366, 369, 387, 389-397, 398, 411-412, 415-416, 700-701, 703-708, 710-714, 716-722, 725-729, 750, 754-75922
19300, 305, 30623
20180-18824
21189-192, 19425
Sheet1
 
Upvote 0
Ive added the spreadsheet I am working on . I will like to breakdown the range 001-999 but still make sure they are still aligned to the number column. As you see there are ranges and single number combos. Thank you
 
Upvote 0
That doesn't clarify what you're looking for as solution.
Is that long string of numbers in ONE cell and then you want them broken out into multiple rows?
That is correct, break them into multiple rows of single digits but keep the columns with them. Thanks
 
Upvote 0
Sorry I'm not getting it. If A2 is, as you show, 001-999, then you want column E to have the numbers from 001 to 999 but with column F having a 5?
Then, if A3 has that same range again, you want another 100 rows in E but with F having a 6?

Ultimately, you might have 1000s of rows??
 
Upvote 0
Give this macro a try with a copy of your workbook.

To implement ..
1. With your workbook active press Alt+F11 to bring up the vba window.
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Press Alt+F8 to bring up the Macro dialog
6. Select the SplitEm macro & click ‘Run’
7. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)


VBA Code:
Sub SplitEm()
  Dim a As Variant, b As Variant, itm As Variant
  Dim i As Long, j As Long, k As Long, num As Long
  
  a = Range("A2", Range("B" & Rows.Count).End(xlUp)).Value2
  ReDim b(1 To Rows.Count, 1 To 2)
  For i = 1 To UBound(a)
    num = a(i, 2)
    For Each itm In Split(Replace(a(i, 1), " ", ""), ",")
      For j = Split(itm, "-")(0) To Split(itm & "-" & itm, "-")(1)
        k = k + 1
        b(k, 1) = j: b(k, 2) = num
      Next j
    Next itm
  Next i
  Range("E2:F2").Resize(k).Value = b
End Sub
 
Upvote 0
Sorry I'm not getting it. If A2 is, as you show, 001-999, then you want column E to have the numbers from 001 to 999 but with column F having a 5?
Then, if A3 has that same range again, you want another 100 rows in E but with F having a 6?

Ultimately, you might have 1000s of rows??
Kweaver, that is exactly what I was looking for. thank you
 
Upvote 0
Give this macro a try with a copy of your workbook.

To implement ..
1. With your workbook active press Alt+F11 to bring up the vba window.
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Press Alt+F8 to bring up the Macro dialog
6. Select the SplitEm macro & click ‘Run’
7. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)


VBA Code:
Sub SplitEm()
  Dim a As Variant, b As Variant, itm As Variant
  Dim i As Long, j As Long, k As Long, num As Long
 
  a = Range("A2", Range("B" & Rows.Count).End(xlUp)).Value2
  ReDim b(1 To Rows.Count, 1 To 2)
  For i = 1 To UBound(a)
    num = a(i, 2)
    For Each itm In Split(Replace(a(i, 1), " ", ""), ",")
      For j = Split(itm, "-")(0) To Split(itm & "-" & itm, "-")(1)
        k = k + 1
        b(k, 1) = j: b(k, 2) = num
      Next j
    Next itm
  Next i
  Range("E2:F2").Resize(k).Value = b
End Sub
Peter_SSs, thanks for sharing this code. Unfortunately my excel is not giving vba option. Can I put this in access as well.
 
Upvote 0
That's a great approach, Paul...but I got an error on the line just above "End Sub"

1621952290127.png


Code:
Range("E2:F2").Resize(k).Value = b

My columns are only A and B. Am I missing something here?

MergeCells05202021.xlsm
AB
1RangeNumber
2002-0095
3007-0106
41437
5501-5128
6600-6068
SheetA
 
Upvote 0

Forum statistics

Threads
1,215,779
Messages
6,126,843
Members
449,343
Latest member
DEWS2031

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