复制excel行的次数与行中单元格中的数量相同。重命名重复行中的单元格

时间:2014-07-29 12:14:43

标签: excel vbscript duplicate-data

我想多次复制一行:

WO      Desc    Quantity    Start       End         Sublot

210000  xxxyyy  2460        2014 07 31  2014 08 05  400

重复行的数量为Quantity / Sublot + 1 根据行数,WO单元将被重命名为210000_1,_2等。 数量将等于子时间,最后一行将是余数(在这种情况下为60)

WO          Desc    Quantity    Start       End         Sublot

210000_1    xxxyyy  400         2014 07 31  2014 08 05  400

210000_2    xxxyyy  400         2014 07 31  2014 08 05  400

210000_3    xxxyyy  400         2014 07 31  2014 08 05  400

210000_4    xxxyyy  400         2014 07 31  2014 08 05  400

210000_5    xxxyyy  400         2014 07 31  2014 08 05  400

210000_6    xxxyyy  400         2014 07 31  2014 08 05  400

210000_7    xxxyyy  60          2014 07 31  2014 08 05  400

有人会有一段代码吗? 谢谢!

2 个答案:

答案 0 :(得分:0)

不幸的是我的Excel是德语。 在左侧的结果,在右侧的公式 (译注:

wenn=if
runden=round
zeile=line/row
rest=modulo/remainder of a division

; is used to separate parameters the english version uses , afaik

希望有所帮助

Excel Solution

答案 1 :(得分:0)

好的,做到了:

Sub insertrows()
Dim x As Long
Dim split As Integer
Dim rowstepper As Integer
Dim currow As Integer
Dim total As Integer
Dim remain As Integer
Dim sublot As Integer
Dim sublotcount As Integer
rowstepper = 1
currow = 1
split = Cells(rowstepper, 7).Value
total = Cells(rowstepper, 2).Value
sublot = Cells(rowstepper, 8).Value
remain = total
sublotcount = Cells(rowstepper, 7).Value
Do
split = Cells(rowstepper, 7).Value
total = Cells(rowstepper, 2).Value
sublot = Cells(rowstepper, 8).Value
remain = total
sublotcount = Cells(rowstepper, 7).Value
For x = 1 To split
    Rows(x + rowstepper).Resize(1).Insert
    Cells(x + rowstepper, 1) = Cells(rowstepper, 1).Value & "_" & x
    total = total - sublot
    remain = remain - sublot
    If total > remain - (sublotcount - 1) * sublot Then
        Cells(x + rowstepper, 3) = sublot
    Else
        Cells(x + rowstepper, 3) = sublot + remain
    End If
    sublotcount = sublotcount - 1
    currow = rowstepper + split + 1
Next x
    rowstepper = currow
Loop While Not Cells(currow, 1).Value = ""
End Sub