ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop & add number list (https://www.excelbanter.com/excel-programming/340125-loop-add-number-list.html)

Whiz Kid

Loop & add number list
 
Hello,

I am try to make a macro that will loop thru about 100 cells and add a
number to the last column. The catch is that I would like the first
four cells to have 1 the next four to have two until you et down to the
last four which would have 25.

It might look like this...

Pam 25 45 1
Joe 45 55 1
Peter 34 12 1
Paul 10 10 1
Alex 23 45 2
Alexis 23 11 2
Abby 11 19 2
Bobby 56 43 2
....
....
....
Tony 34 56 25
Tom 34 33 25
Ted 88 76 25
Tana 33 22 25

I have no problem getting the 1 thru 25 on the first cell however I can
not seem get anything I try to make the next three.

Can anybody help?

Blair


Rowan[_8_]

Loop & add number list
 
If you have data in column A and you want to add the numbers to column D
then maybe:

Sub AddNums()
Dim i As Integer
Dim k As Integer
Dim j As Long
Dim eRow As Long
i = 1
k = 1
eRow = Cells(Rows.Count, 1).End(xlUp).Row
For j = 1 To eRow
Cells(j, 4).Value = i
If k = 4 Then
k = 0
i = i + 1
End If
k = k + 1
Next
End Sub


Hope this helps
Rowan

Whiz Kid wrote:
Hello,

I am try to make a macro that will loop thru about 100 cells and add a
number to the last column. The catch is that I would like the first
four cells to have 1 the next four to have two until you et down to the
last four which would have 25.

It might look like this...

Pam 25 45 1
Joe 45 55 1
Peter 34 12 1
Paul 10 10 1
Alex 23 45 2
Alexis 23 11 2
Abby 11 19 2
Bobby 56 43 2
...
...
...
Tony 34 56 25
Tom 34 33 25
Ted 88 76 25
Tana 33 22 25

I have no problem getting the 1 thru 25 on the first cell however I can
not seem get anything I try to make the next three.

Can anybody help?

Blair


Patrick Molloy[_2_]

Loop & add number list
 

Sub test_loop()
Dim iRowIndex As Long
For iRowIndex = 1 To Range("A65000").End(xlUp).Row
Cells(iRowIndex, 4) = Int((iRowIndex + 3) / 4)
Next
End Sub


"Whiz Kid" wrote:

Hello,

I am try to make a macro that will loop thru about 100 cells and add a
number to the last column. The catch is that I would like the first
four cells to have 1 the next four to have two until you et down to the
last four which would have 25.

It might look like this...

Pam 25 45 1
Joe 45 55 1
Peter 34 12 1
Paul 10 10 1
Alex 23 45 2
Alexis 23 11 2
Abby 11 19 2
Bobby 56 43 2
....
....
....
Tony 34 56 25
Tom 34 33 25
Ted 88 76 25
Tana 33 22 25

I have no problem getting the 1 thru 25 on the first cell however I can
not seem get anything I try to make the next three.

Can anybody help?

Blair




All times are GMT +1. The time now is 07:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com