[英]Copy and paste down a column based on the value of another cell
我試圖將一個數字復制並粘貼到一列(該數字將在整個“A”列中變化)並且我需要在列中填充單元格的實例數量等於數據集中另一個單元格的值。 該值也將隨之變化。 任何幫助,將不勝感激。 如果值為3751022,則另一列中的值為11
The image shows the set Im working on. It need to copy down 3751022 down column A 1-11 times because the first entry will already be done. once the 10 are pasted then it needs to wait for the next entry to past another value down x amount of time
我不完全明白你會在哪里得到你想重復的價值,但你可以建立一個像這樣的函數
Public Function Copy2()
Dim r1, r2, r3 As Range
Dim ct
Set r1 = Range("a1") 'set pointer
Set r2 = Range("b1") 'set pointer
Set r3 = Range("c1") 'set pointer
Do ' outer loop going through each number in column A until it comes up to a blank cell
ct = 0
Do ' Inner loop printing the # of times a number is requested from coresponding colum B data
ct = ct + 1
' prints column 3 info
r3.Value = r1.Value
Set r3 = r3.Offset(1, 0)
Loop Until ct = r2.Value
Set r2 = r2.Offset(1, 0)
Set r1 = r1.Offset(1, 0)
Loop Until r1.Value = ""
End Function
然后你可以從一個按鈕調用它,你可以在其中分配它的代碼
Private Sub CommandButton2_Click()
Copy2
End Sub
這將從A列開始,並開始填充新列C,其中列C的相應列B中找到的出現次數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.