ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro to list numbers (https://www.excelbanter.com/excel-programming/337875-macro-list-numbers.html)

tryer[_4_]

macro to list numbers
 

I have a column of numbers say 1 to 10 in column A
In column B at various rows there could be a number. This is the number
of times I need the number in column A repeated in column C eg.
A B C
1 3
2 3
3 3 3
4 2 4
5 2 4
6 1 5
7 5
8 6
9 10
10 1
I have been trying to write a macro for this. I have got as far as
going down column A and identifying how many rows are populated and
then got stuck.
Help would be appreciated


--
tryer
------------------------------------------------------------------------
tryer's Profile: http://www.excelforum.com/member.php...o&userid=16546
View this thread: http://www.excelforum.com/showthread...hreadid=397590


Richard Buttrey

macro to list numbers
 
On Sun, 21 Aug 2005 12:24:59 -0500, tryer
wrote:


I have a column of numbers say 1 to 10 in column A
In column B at various rows there could be a number. This is the number
of times I need the number in column A repeated in column C eg.
A B C
1 3
2 3
3 3 3
4 2 4
5 2 4
6 1 5
7 5
8 6
9 10
10 1
I have been trying to write a macro for this. I have got as far as
going down column A and identifying how many rows are populated and
then got stuck.
Help would be appreciated


One solution

Sub Repeater()
Dim a As Integer, b As Integer, x As Integer, y As Integer, count As
Integer

For x = 0 To Range("A1").CurrentRegion.Rows.count

If Range("A1").Offset(x, 1) < "" Then
b = Range("A1").Offset(x, 1)
a = Range("A1").Offset(x, 0)

For y = 1 To b
Range("c1").Offset(count + y - 1, 0) = a
Next
count = count + b

End If
Next

End Sub

__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________


All times are GMT +1. The time now is 05:08 AM.

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