简体   繁体   English

复制和粘贴单元格值“X”次然后循环到下一行

[英]Copy & Paste Cell Value “X” amount of times then loop to next row

Details:细节:

  1. Copy cell value in column D IF YR value is 1, paste starting in column G如果 YR 值为 1,则复制 D 列中的单元格值,从 G 列开始粘贴
  2. This repeats in each row for counter # of times IE if counter is 5, copy & paste cell value from G to K这在每行中重复计数器 # 次 IE 如果计数器为 5,则将单元格值从 G 复制并粘贴到 K
  3. Once counter is expired, move to next row and repeat process一旦计数器过期,移动到下一行并重复过程

Screen Shot of Excel Excel 的屏幕截图
在此处输入图像描述

Dim StartRow As Byte
Dim LastRow As Long
Dim i As Integer
Dim ii As Integer
Dim cnt As Integer

StartRow = 3
LastRow = Range("B3").CurrentRegion.Rows.Count - 1

For i = StartRow To LastRow
    cnt = Range("C" & i).Value
    For ii = 1 To cnt
        If Range("B" & StartRow) = 1 Then
            Range("D" & StartRow).Copy
            Range("B" & StartRow).End(xlToRight).Offset(0, ii + 2).PasteSpecial (xlPasteAll)
        End If
    Next ii
Next i

You may try this:你可以试试这个:

Dim StartRow As Byte
Dim LastRow As Long
Dim i As Integer
Dim ii As Integer
Dim cnt As Integer
Dim limitCol As Integer

StartRow = 3
LastRow = Range("B3").CurrentRegion.Rows.Count - 1

For i = StartRow To LastRow
    If (CInt(Range("B" & i)) = 1) Then
        cnt = Range("C" & i).Value
        limitCol = cnt + 6
        For ii = 7 To limitCol
            Cells(i, ii) = Range("D" & i).Value
        Next ii
    End If
Next i

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

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