Excel宏,要基于另一个单元格值复制并粘贴一个单元格值? [英] Excel macro, to copy and paste a cell value based on another cell value?

查看:93
本文介绍了Excel宏,要基于另一个单元格值复制并粘贴一个单元格值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将尽力清楚地说明我需要做的事情:

Hi I shall try to explain clearly what I need to be able to do, here goes:

我有一个Excel电子表格1,在 A 列中有邮政编码,在 B 列中有一个数字.我需要创建一个宏/公式,以便它将看到数字(即3),并将该次数的邮政编码复制并粘贴到彼此下面的工作表2列a中.我需要对下一行等执行此操作,直到出现空白为止.

I have an Excel spread sheet 1 with postcodes in column A and a number in column B. I need to create a macro/formula so that it will see the number (i.e 3) and copy and paste the postcode that number of times into sheet 2 column a underneath each other. I need to do this for the next row down etc until it comes to a blank.

第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

这篇关于Excel宏,要基于另一个单元格值复制并粘贴一个单元格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆