generate sequence of number

  • Thread starter cyzax7 via OfficeKB.com
  • Start date
C

cyzax7 via OfficeKB.com

hello there,

I have prob with my code that need your guide. I want to create a macro that
will generate numbers starting from 0 to 6 000 000 000 in Column A when user
click on the command button(Generate_Numbers). The numbers are in multiple of
50000. Below are the code: When I tried to debug the code, a message box
displayed showing a run time error.. Can someone show me where is the
mistakes ??

Sub Generate_Numbers()
Dim CountRow As Integer
Dim i As Double


For CountRow = 2 To cLastRow = 120000
i = 0
Worksheets("Data2").Cells(CountRow, "A").Value = i
i = i + 500000
CountRow = CountRow + 1
Next CountRow

End Sub

********Generate numbers command button in Worksheet ("Data2")
****************

Private Sub GenerateNumCommandButton1_Click()
Generate_Numbers
End Sub

**************************************************************************


tq
 
R

RB Smissaert

You want something like this:

Sub Generate_Numbers()

Dim CountRow As Long
Dim cLastRow As Long
Dim i As Double

cLastRow = 100

For CountRow = 2 To cLastRow
Worksheets("Data2").Cells(CountRow, 1).Value = i
i = i + 500000
Next CountRow

End Sub


RBS
 
C

cyzax7 via OfficeKB.com

Hi RB Smissaert,

Thanxs.. It works so well ;>


RB said:
You want something like this:

Sub Generate_Numbers()

Dim CountRow As Long
Dim cLastRow As Long
Dim i As Double

cLastRow = 100

For CountRow = 2 To cLastRow
Worksheets("Data2").Cells(CountRow, 1).Value = i
i = i + 500000
Next CountRow

End Sub

RBS
hello there,
[quoted text clipped - 31 lines]
 

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