简体   繁体   English

根据另一个单元格的值复制并粘贴一列

[英]Copy and paste down a column based on the value of another cell

I am trying to copy and paste a number down a column ( that number will vary throughout column "A") and I need the number of Instances that a cell is filled down the column to equal the value of another cell in the data set. 我试图将一个数字复制并粘贴到一列(该数字将在整个“A”列中变化)并且我需要在列中填充单元格的实例数量等于数据集中另一个单元格的值。 That value will vary throughout as well. 该值也将随之变化。 Any help would be appreciated. 任何帮助,将不胜感激。 if the value was 3751022 and the value in the other column was 11 如果值为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                                                

I don't completely understand where you will get the value you want repeated but you could build a function like 我不完全明白你会在哪里得到你想重复的价值,但你可以建立一个像这样的函数

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

Then you can call it from a button where you would assign its code like 然后你可以从一个按钮调用它,你可以在其中分配它的代码

Private Sub CommandButton2_Click()
Copy2
End Sub

this will go down column A and starting populating a new column C with the number of occurrences found in its respective column B 这将从A列开始,并开始填充新列C,其中列C的相应列B中找到的出现次数

example result 示例结果

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

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