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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
54,296
Office Version
  1. 365
Platform
  1. Windows
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>
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,916
Messages
5,834,366
Members
430,281
Latest member
fabcat1

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
Top