![](/img/trans.png)
[英]Excel macro, to copy and paste a multiple cells based on another cell value?
[英]Excel macro, to copy and paste a cell value based on another cell value?
嗨,我将尽力清楚地说明我需要做的事情,这是:
我有一个Excel电子表格1,在A
列中有邮政编码,在B
列中A
一个数字。 我需要创建一个宏/公式,以便它将看到数字(即3),并将该次数的邮政编码复制并粘贴到彼此下面的工作表2列a中。 我需要对下一行等执行此操作,直到出现空白为止。
工作表1
A B
DE43PP 3
DE43PQ 8
工作表2
A B
DE43PP
DE43PP
DE43PP
DE43PQ
...
谢谢
尝试这个:
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.