EXCEL在新工作表上插入数据+顺序编号

时间:2018-06-27 18:20:12

标签: excel numbers sequential

我找到了一个代码,用于根据数量值将数据复制到新表中。我正在使用此代码创建运输标签,并且需要有关在“ B”列中添加顺序编号的指导。我引用了先前有关顺序编号的文章,但无法将数据复制到单独的图纸上。

Excel: Sequential numbers + specified start and end values + shift column data down

' This routing will copy rows based on the quantity to a new sheet.
Dim rngSinglecell As Range
Dim rngQuantityCells As Range
Dim intCount As Integer

' Set this for the range where the Quantity column exists. This works only if there are no empty cells
Set rngQuantityCells = Sheets("SHIP LABEL DATA").Range("C2", Sheets("SHIP LABEL DATA").Range("C2").End(xlDown))

' Clear data from reference sheet
Application.ScreenUpdating = False
Sheets("SHIP LABEL REF").Rows("3:300").ClearContents

For Each rngSinglecell In rngQuantityCells

    ' Check if this cell actually contains a number
    If IsNumeric(rngSinglecell.Value) Then
        ' Check if the number is greater than 0
        If rngSinglecell.Value > 0 Then
            ' Copy this row as many times as .value
            For intCount = 1 To rngSinglecell.Value
                ' Copy the row into the next emtpy row in sheet(SHIP LABEL REF)
                Application.ScreenUpdating = False
                Sheets("SHIP LABEL DATA").Range(rngSinglecell.Address).EntireRow.Copy
                Sheets("SHIP LABEL REF").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

                ' The above line finds the next empty row.
            Next
            Application.CutCopyMode = False
            Application.ScreenUpdating = True
        End If
    End If
Next

结束子

enter image description here enter image description here

0 个答案:

没有答案