Creating a list of numbers using Loop

Johnwayne

Board Regular
Joined
Sep 6, 2005
Messages
103
Hi, my question is pretty simple.

i just need to know how to i create a list of numbers in Column B range from B10 to B200.

i will key in a number in A1, lets say 50
once i key 50 in "A1"
excel will loop and input numbers to B1 to B200
from 1 to 50 and it will stop once it reach 50.
eg.

B1 will show 1
b2 will show 2
b3 will show 3
up to 50 and will stop there

can it be done, please advise. im quite new in the loop function
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi

When you say "will stop at 50" do you mean then that you will only have values in B1:B50? Do you need to do this in a loop? You could use the AutoFill method which would be faster and more succinct.
 
Upvote 0
No need for a loop.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        Application.EnableEvents = False
        Range("B:B").ClearContents
        Range("B1") = "1"
        Range("B1:B" & Target.Value).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
            Step:=1, Stop:=Target.Value, Trend:=False
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
norie..

Can it be done using the loop function
what if my input is in A1 but the cell i want it to be numbered start from B3 onwards...
?
 
Upvote 0
Yes it could be done using a loop, but why use a loop when you don't need one?

Is there something more to what you want to do?

As to starting in B3, easily done.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        Application.EnableEvents = False
        Range("B:B").ClearContents
        Range("B3") = "1"
        Range("B3").Resize(Target.Value).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
            Step:=1, Stop:=Target.Value, Trend:=False
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,847
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