【问题标题】:Excel How To Repeat multiple values based on a Cell Value X TimesExcel如何根据单元格值重复多个值X次
【发布时间】:2017-10-27 16:21:06
【问题描述】:

致任何可以提供帮助的人...提前致谢。

每行商品编号、包装和尺寸都需要根据“标签数量”列中的数字在单独的表格中重复多次

请注意:标签数量中的数字仅供测试使用,不需要递增

表 1 如下

Item #  Pack    Size    Number of Labels
12545   20      1.8oz   1
56010   6       4PK     2
70091   6       7oz     3
61816   24      1.6oz   4

4

我希望工作表 2 输出如下内容:

Item #  Pack    Size
12545   20      1.8oz
56010   6        4PK
56010   6        4PK
70091   6        7oz
70091   6        7oz
70091   6        7oz
61816   24       1.6oz
61816   24       1.6oz
61816   24       1.6oz
61816   24       1.6oz

我找到了以下代码,但我希望修复单元格输入范围并且不使用对话框我需要帮助修改我找到的代码才能解决给定的问题。我需要以下代码来输出多个列。 : (我在这里得到了代码:https://www.extendoffice.com/documents/excel/1897-excel-repeat-cell-value-x-times.html#a2

Sub CopyData()
'Update 20140724
Dim Rng As Range
Dim InputRng As Range, OutRng As Range
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Set OutRng = OutRng.Range("A1")
For Each Rng In InputRng.Rows
    xValue = Rng.Range("A1").Value
    xNum = Rng.Range("B1").Value
    OutRng.Resize(xNum, 1).Value = xValue
    Set OutRng = OutRng.Offset(xNum, 0)
Next
End Sub

我试图做的黑客攻击没有任何帮助会很棒。

背景:我必须在工作中为新产品创建许多标签。我必须在 Word 中手动输入每个标签。我发现我可以使用 Words Mail 合并操作来导入 Excel 数据。我让这些部件正常工作,但现在我需要能够获得每个项目所需的确切标签数量。

【问题讨论】:

    标签: excel vba copying


    【解决方案1】:
    Private Sub hereyago()
    
        Dim arr As Variant
        Dim wsO As Worksheet
        Dim this As Integer
    
        arr = ThisWorkbook.Sheets("Sheet1").UsedRange
        Set wsO = ThisWorkbook.Sheets("Sheet2")
    
        For i = LBound(arr, 1) To UBound(arr, 1)
            If IsNumeric(arr(i, 4)) Then
                this = arr(i, 4)
                For h = 1 To this
                    wsO.Cells(wsO.Rows.count, 1).End(xlUp).Offset(1, 0).Value = arr(i, 1)
                    wsO.Cells(wsO.Rows.count, 1).End(xlUp).Offset(0, 1).Value = arr(i, 2)
                    wsO.Cells(wsO.Rows.count, 1).End(xlUp).Offset(0, 2).Value = arr(i, 3)
                    wsO.Cells(wsO.Rows.count, 1).End(xlUp).Offset(0, 3).Value = arr(i, 4)
                Next h
            End If
        Next i
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2021-12-09
      • 2017-09-23
      • 2014-12-27
      • 2014-10-13
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      相关资源
      最近更新 更多