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
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

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
45,926
Office Version
365
Platform
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>
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,886
Messages
5,513,981
Members
408,980
Latest member
Naomi_

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top