开发者

Create additional rows in excel

How can I add new rows from:-

Column A        Column B         Column C
11               Size              S
11               Color             Yellow
11               Type              Q
22               Size              M
22               Color             Blue
22               Type              W
33               Size              L
33               Color             Brown
33               Type              R

to this in excel:-

Column A        Column B         Column C
11               Size              S
11               Color             Yellow
11               Type              Q
11               Model             T1
11               Grade             1
11               LotNo             Z10
22               Size              M
22               Color             Blue
22               Type              W
22               Model             T2
2开发者_运维技巧2               Grade             1
22               LotNo             M10
33               Size              L
33               Color             Brown
33               Type              R
33               Model             T3
33               Grade             2
33               LotNo             C10

Thanks,

Bob


Assuming you mean doing this in VBA (since it's tagged macros and this is a programming Q&A site), you can insert and populate a row with code like:

Range("A3").EntireRow.Insert
Range("A3").Formula = "=11"
Range("B3").Value = "Hello"

Everything else is just figuring out a loop which will do the whole thing. The code below will expand the rows as you desire (by adding Model, Grade and LotNo rows after each Type row). The actual values of those items are left as ?? since it's not clear how to calculate them from the other data.

Sub Macro1()
    Dim Row As Integer
    Row = 1
    While Range("B" & Row).Value <> ""
        Row = Row + 1
    Wend
    While Row <> 1
        If Range("B" & (Row - 1)).Value = "Type" Then
            Range("A" & Row).EntireRow.Insert
            Range("A" & Row).Formula = Range("A" & (Row - 1)).Formula
            Range("B" & Row).Value = "LotNo"
            Range("C" & Row).Value = "??"

            Range("A" & Row).EntireRow.Insert
            Range("A" & Row).Formula = Range("A" & (Row - 1)).Formula
            Range("B" & Row).Value = "Grade"
            Range("C" & Row).Value = "??"

            Range("A" & Row).EntireRow.Insert
            Range("A" & Row).Formula = Range("A" & (Row - 1)).Formula
            Range("B" & Row).Value = "Model"
            Range("C" & Row).Value = "??"

        End If
        Row = Row - 1
    Wend
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜