[英]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.