Hello,
I have a simple macro that I am trying to create. I haven't done programming in Basic in several years but I used to could do a nested loop to perform multiple repeats. Anyway, I have a small spreedsheet that has two rows of numbers. In column "A" are numbers that repeat for several rows and in column "C" are corresponding numbers that are associated with those in column "A". I am trying to write a macro that will add the numbers in column "C" until the numbers in column "A" stop repeating, post those numbers on a separate sheet, then go back to the original sheet and pick up where it left off. The output would be the sum of the numbers in column "C" plus the count of the numbers that repeat in column "A". I can program to do this one time and can not get it to pick up where it left off to add the reamining numbers. Once the numbers in column "A" stop repeating I need the program to continue with the next set of numbers until there are no more numbers.
The data looks something like this:
Column "A" Column "C"
1................... 43
1 ...................36
1 ...................14
1 .....................8
1 ....................34
1 ....................23
2 ...................15
2 ...................12
2.................... 12
2.................... 89
the output would look something like
#.....................sum of #
5.................... 158
4 ....................128
I need the macro to continue until it there no more numbers in column "A".
I can get it to work for the "1's but can not get it to go back and start with the 2's.
This is my program so far:
Sub CountRows()
x = 3
y = 3
(the data starts in row 3 and has a header that I want to skip)
Do While Cells(x, 3).Value <> ""
Do While Cells(x, 3).Value <> ""
If Cells(x, 3).Value = Cells(x + 1, 3).Value Then z = z + 1 Else GoTo 1
total = total + Cells(x, y + 2).Value
x = x + 1
Loop
1 total = total + Cells(x, y + 2).Value
z = z + 1
K = 0
Sheets("sheet1").Select
Cells(K + 1, 1).Value = z
Cells(K + 2, 1).Value = total
Sheets("Names").Select
Loop
End Sub
What can I do to get it to repeat with the next set of numbers?
Thanks alot.
I have a simple macro that I am trying to create. I haven't done programming in Basic in several years but I used to could do a nested loop to perform multiple repeats. Anyway, I have a small spreedsheet that has two rows of numbers. In column "A" are numbers that repeat for several rows and in column "C" are corresponding numbers that are associated with those in column "A". I am trying to write a macro that will add the numbers in column "C" until the numbers in column "A" stop repeating, post those numbers on a separate sheet, then go back to the original sheet and pick up where it left off. The output would be the sum of the numbers in column "C" plus the count of the numbers that repeat in column "A". I can program to do this one time and can not get it to pick up where it left off to add the reamining numbers. Once the numbers in column "A" stop repeating I need the program to continue with the next set of numbers until there are no more numbers.
The data looks something like this:
Column "A" Column "C"
1................... 43
1 ...................36
1 ...................14
1 .....................8
1 ....................34
1 ....................23
2 ...................15
2 ...................12
2.................... 12
2.................... 89
the output would look something like
#.....................sum of #
5.................... 158
4 ....................128
I need the macro to continue until it there no more numbers in column "A".
I can get it to work for the "1's but can not get it to go back and start with the 2's.
This is my program so far:
Sub CountRows()
x = 3
y = 3
(the data starts in row 3 and has a header that I want to skip)
Do While Cells(x, 3).Value <> ""
Do While Cells(x, 3).Value <> ""
If Cells(x, 3).Value = Cells(x + 1, 3).Value Then z = z + 1 Else GoTo 1
total = total + Cells(x, y + 2).Value
x = x + 1
Loop
1 total = total + Cells(x, y + 2).Value
z = z + 1
K = 0
Sheets("sheet1").Select
Cells(K + 1, 1).Value = z
Cells(K + 2, 1).Value = total
Sheets("Names").Select
Loop
End Sub
What can I do to get it to repeat with the next set of numbers?
Thanks alot.
Last edited: