簡體   English   中英

復制和粘貼單元格值“X”次然后循環到下一行

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

細節:

  1. 如果 YR 值為 1,則復制 D 列中的單元格值,從 G 列開始粘貼
  2. 這在每行中重復計數器 # 次 IE 如果計數器為 5,則將單元格值從 G 復制並粘貼到 K
  3. 一旦計數器過期,移動到下一行並重復過程

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

你可以試試這個:

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