[英]Excel macro, to copy and paste a cell value based on another cell value?
Hi I shall try to explain clearly what I need to be able to do, here goes: 嗨,我将尽力清楚地说明我需要做的事情,这是:
I have an Excel spread sheet 1 with postcodes in column A
and a number in column B
. 我有一个Excel电子表格1,在
A
列中有邮政编码,在B
列中A
一个数字。 I need to create a macro/formula so that it will see the number (ie 3) and copy and paste the postcode that number of times into sheet 2 column a underneath each other. 我需要创建一个宏/公式,以便它将看到数字(即3),并将该次数的邮政编码复制并粘贴到彼此下面的工作表2列a中。 I need to do this for the next row down etc until it comes to a blank.
我需要对下一行等执行此操作,直到出现空白为止。
Sheet 1 工作表1
A B
DE43PP 3
DE43PQ 8
Sheet 2 工作表2
A B
DE43PP
DE43PP
DE43PP
DE43PQ
...
Thanks 谢谢
Try this: 尝试这个:
Sub copyPostcodes()
Dim c As Range
Dim x As Long
Dim y As Long
y = 0
For Each c In Sheets("Sheet1").Range("A:A").Cells
If Len(c) > 0 Then
For x = 1 To c.Offset(0, 1)
Sheets("Sheet2").Range("A1").Offset(y, 0) = c
y = y + 1
Next x
End If
Next c
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.