【发布时间】:2015-07-24 02:32:19
【问题描述】:
在 Excel 中,我需要为批量上传生成文件,其中包含 1K、5K、10K 和 100K 行。所以我查看了 VBA 脚本。下面是:
Private Sub CommandButton21_Click()
' 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 = Range("D1", Range("D1").End(xlDown))
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 cut out rngSinglecell DOT Value
For intCount = 1 To 1000
' Copy the row into the next emtpy row in sheet2
Range(rngSinglecell.Address).EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
' The above line finds the next empty row.
Next
End If
End If
Next
End Sub
但我想要做的是复制从 A15 到 Y15 的一行数据,然后将其粘贴到工作表中,以便我可以将其复制粘贴回原始工作表(用于 iProcurement 中的批量上传)。
由于某种原因,我的行只被复制了两次,即使我将 intcount 更改为以下内容:
For intCount = 1 To 1000
感谢任何提示,谢谢!
【问题讨论】:
-
您在同一输出行上复制了 1000 次。
-
您想复制 D 列中单元格指定的次数吗?
-
@RBarryYoung - 好的,我会再研究一下,谢谢!
-
@Raystafarian - 不确定我明白你的意思。 > 的 D 列是什么?
-
您指定了 D 列。我不确定您对这个宏的意图是什么。