Change the line that says
FirstRow = 2 'headers in row 1???
to
FirstRow = 1 'headers in row 1???
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Melissa" wrote in message
...
I tested the code on this data:
Adam 5
Brian 4
Carl 3
in worksheet 1, A1:B3.
Then I copied the code as per what you provided into a new macro. The
result I got was:
Adam 5
Brian 1
Brian 2
Brian 3
Brian 4
Carl 1
Carl 2
Carl 3
Brian and Carl are working fine, i.e. 4 rows for B and 3 for C. But Adam
remains as just a single row with the value "5" next to it. What am I
doing
wrong?
"Dave Peterson" wrote:
Try this against a copy of your workbook--it'll destroy the original
data.
Option Explicit
Sub testme()
Dim wks As Worksheet
Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim howMany As Long
Set wks = Worksheets("sheet1")
With wks
FirstRow = 2 'headers in row 1???
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
howMany = .Cells(iRow, "B").Value
If howMany 1 Then
.Rows(iRow + 1).Resize(howMany - 1).Insert
.Cells(iRow, "A").Resize(howMany).Value _
= .Cells(iRow, "A").Value
With .Cells(iRow, "B").Resize(howMany)
.Formula = "=row()-" & iRow - 1
.Value = .Value
End With
End If
Next iRow
End With
End Sub
If you're new to macros, you may want to read David McRitchie's intro
at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
And there's no validation against the value in column B. It can blow up
really
good if you don't type in nice numbers.