+ Reply to Thread
Results 1 to 3 of 3

Loop & add number list

Hybrid View

Guest Loop & add number list 09-15-2005, 12:05 AM
Guest Re: Loop & add number list 09-15-2005, 01:05 AM
Guest RE: Loop & add number list 09-15-2005, 03:05 AM
  1. #1
    Whiz Kid
    Guest

    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. #2
    Rowan
    Guest

    Re: 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. #3
    Patrick Molloy
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1