-1

我想知道是否可以创建一个宏,将复制范围中的每个单元格多次粘贴(x)在一列中。

例如。我们有这样的数据
a
b
c
...我们需要 (
例如 x=4)
a
a
a
a
b
b
b
c
c
c
c

4

1 回答 1

0

请试试这个:

Sub pCreateMultipleTimes()

    Dim strText             As String
    Dim strOutput           As String
    Dim intMultiplier       As Integer
    Dim varTempData         As Variant
    Dim lngLoop1            As Long
    Dim lngLoop2            As Long

    'Considering data to be in form so it will be in text
    strText = "a b c"

    ' x=4
    intMultiplier = 4

    'Split Text with space as delimiter and assign it to Variant
    varTempData = Split(strText, " ")

    'Loop through to create the final combination output
    For lngLoop1 = LBound(varTempData) To UBound(varTempData)
        For lngLoop2 = 1 To intMultiplier
            strOutput = Trim(strOutput & " " & varTempData(lngLoop1))
        Next lngLoop2
    Next lngLoop1
    MsgBox "Your needed Output is: " & strOutput, vbOKOnly + vbInformation

End Sub
于 2014-10-13T14:34:18.323 回答