Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through drop down list mcousin Excel Worksheet Functions 0 February 7th 11 06:55 PM
loop a list with the IF formula ufo_pilot Excel Discussion (Misc queries) 1 January 21st 08 10:10 PM
For loop with non consecutive number zapatista66 Excel Programming 5 July 30th 04 01:36 PM
loop random number mrmark Excel Programming 4 June 22nd 04 03:14 PM
For Loop in Filtered List Hafeez Esmail Excel Programming 0 December 18th 03 05:48 PM


All times are GMT +1. The time now is 10:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"