Simple Excel Question!

M

Mike

Hi everyone,

Sa you have this in cell A1 a max value of 10. In B column I then
have:
1
2
3
4
5
6
7
8
9
10


Now, assume the max value in cell A1 is 5 or 20 instead. I want the
numbers automaticall to be listed from 1-to-5 or from 1-to- 20...and
so on.


How can I auotomate this?


Thanks,
Mike
 
G

Gord Dibben

Sub CreateNums()
Dim i As Integer
If Range("A1") = "" Then
Exit Sub
Else
Columns(2).ClearContents
For i = 1 To Range("A1").Value
Cells(i, 2).Value = i
Next i
End If
End Sub

This could also be written as a sheet event.


Gord Dibben MS Excel MVP
 
D

dranon

In cell B1 put:

=IF(A1>0,ROW(),"")

and copy that down to rows 2 through 20 in column B.

If that doesn't do it, explain your problem in greater detail.
 
D

dranon

Enter this formula:

B1: =IF(ROWS($1:1)<$A$1,ROWS($1:1),"")

and fill down to at least as many rows as might represent the maximum
number you might put into A1.

Doesn't work. Try:

B1: =IF(ROWS($1:1)<$A$1+1,ROWS($1:1),"")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top