Converting a range of numbers into single numbers

Flash0220

Board Regular
Joined
May 2, 2002
Messages
104
Hello,


I'm having the following little problem, and i'm hoping that someone here can help me solve it.

I have a sheet called "Ranges" containing the following data.

Column A Column B
1 100
2000 4444

What i would like to do is the following.

The ranges above (1 to 100 and 2000 to 4444) have to be converted
to single numbers on a sheet called "Single numbers".

So something like this.

1
2
3
4
..
..
100
2000
2001
2002
..
..
4444

Is there a simple way to do this in VBA ?
Thanks. :)


Flash
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try

Code:
Sub test()
Dim LR As Long, i As Long, j As Long
With Sheets("Ranges")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        For j = .Range("A" & i).Value To .Range("B" & i).Value
            Sheets("Single numbers").Range("A" & Rows.Count).End(xlUp).Offset(1).Value = j
        Next j
    Next i
End With
End Sub
 
Upvote 0
Another way (I've assumed the 'Ranges' data starts in A2 - adjust code if not)

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Single_Numbers()<br>    <SPAN style="color:#00007F">Dim</SPAN> rCel <SPAN style="color:#00007F">As</SPAN> Range<br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Worksheets("Ranges")<br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> rCel <SPAN style="color:#00007F">In</SPAN> .Range("A2", .Range("A" & Rows.Count).End(xlUp))<br>            <SPAN style="color:#00007F">With</SPAN> Worksheets("Single numbers").Range("A" & Rows.Count).End(xlUp).Offset(1)<br>                .Value = rCel.Value<br>                .Resize(rCel.Offset(, 1).Value - rCel.Value + 1).DataSeries Rowcol:=xlColumns, _<br>                    Type:=xlLinear, Step:=1, Stop:=rCel.Offset(, 1).Value, Trend:=<SPAN style="color:#00007F">False</SPAN><br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN> rCel<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,851
Members
449,051
Latest member
excelquestion515

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