Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling a column data with a number and a count. 1

Status
Not open for further replies.

g16

Technical User
Jun 30, 2003
2
US
What I need advise on is I need to take data from cells A1:A15 (the data in each cell could be a number from 1 to 10) then I have a count of each in cells B1:15. So if A1=1 and B1=3 then I would like Column C to fill in 1 in cells C1:C3. Then A2=4.5 and B2=5 Column C to fill in 4.5 in cells C4:C9. and so on. The data in column A and B will change frequenly.

Thanks in Advance.
 
Here's a simple macro to do what you want:
[blue]
Code:
Sub SetupC()
Const COL_SOURCE = 1
[green]
Code:
'Column "A"
[/color]
Code:
Const COL_COUNTS = 2
[green]
Code:
' Column "B"
[/color]
Code:
Const COL_TARGET = 3
[green]
Code:
' Column "C"
[/color]
Code:
Const ROW_START = 1
Const ROW_END = 15
Dim nSourceRow As Long
Dim nTargetRow As Long
Dim nRow As Long
  Cells(ROW_START, COL_TARGET).EntireColumn.Clear
  nTargetRow = ROW_START
  For nSourceRow = ROW_START To ROW_END
    For nRow = 1 To Cells(nSourceRow, COL_COUNTS)
      Cells(nTargetRow, COL_TARGET) = Cells(nSourceRow, COL_SOURCE)
      nTargetRow = nTargetRow + 1
    Next nRow
  Next nSourceRow
End Sub
[/color]

 
Zathras,
That does exactly what I wanted, thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top