简体   繁体   English

复制/粘贴行 n 次(根据单元格中的值)

[英]copy/paste row n number of times (according to value from cell)

I need a code where cells from column 8 & 14 will be concatenated and copied to another sheet (ofc in first empty cell) but they need to be copied n number of times.我需要一个代码,其中第 8 列和第 14 列的单元格将被连接并复制到另一个工作表(第一个空单元格中的 ofc),但它们需要被复制 n 次。 Depending on value from cell in column 23.取决于第 23 列中单元格的值。

So each copy will be the same, but copied one below other.所以每个副本都将是相同的,但复制一个在另一个下面。

For example:例如:

I have RIF50G 2B in "H2" and MAEU3P in "N2".我在“H2”中有 RIF50G 2B,在“N2”中有 MAEU3P。 In "W2" I have "4".在“W2”中,我有“4”。 So I need this in another sheet:所以我需要在另一张纸上写这个:

RIF50G 2B MAEU3P    
RIF50G 2B MAEU3P    
RIF50G 2B MAEU3P    
RIF50G 2B MAEU3P    

If value in colUmn "W" is 0 that row does not need to be copied!如果列“W”中的值为 0,则不需要复制该行!

Data from all cells mentioned above will be refreshed and each time I run the code, values and strings will be different (it is just a part from larger code where I import some data)来自上面提到的所有单元格的数据将被刷新,每次我运行代码时,值和字符串都会不同(它只是我导入一些数据的较大代码的一部分)

Also, when it finish copying first row this way, I need that to be done for every row until last one.另外,当它以这种方式完成第一行的复制时,我需要对每一行都这样做,直到最后一行。

A simple Range.Resize based on the value in column W should be enough to repeat the concatenated values.基于 W 列中的值的简单Range.Resize应该足以重复连接的值。

Dim rw As Long
With Worksheets("Sheet1")
    For rw = 2 To .Cells(Rows.Count, "W").End(xlUp).Row
        If CBool(.Cells(rw, "W").Value2) Then _
            Worksheets("another sheet").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(.Cells(rw, "W").Value2, 1) = _
                .Cells(rw, "H").Value2 & Chr(32) & .Cells(rw, "N").Value2
    Next rw
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM