从文本框复制文本并粘贴到新工作表的单元格中

时间:2015-03-13 23:41:10

标签: excel vba excel-vba

我正在搜索复制由前一个宏创建的 TextBox 的所有文本并将其粘贴到 Sheet3 上的Cell A1中。

有什么建议吗?

这是以前的宏:

  Sub Copy()
    Dim srng As Range
    Dim sWs As Worksheet: Set sWs = Sheets("Sheet1")
    Set srng = sWs.Range("L1", sWs.Range("L" & sWs.Rows.Count).End(xlUp))
    With Sheets("Sheet4").Shapes("Textbox 2").OLEFormat.Object
        .Text = Join(Application.Transpose(srng), vbCrLf)
    End With
End Sub

1 个答案:

答案 0 :(得分:0)

您可以计算形状。然后将文本放在最高计数文本框中。 例如。

    Sub Copy()
    Dim ws As Worksheet, sh As Worksheet
    Dim Rws As Long, Rng As Range
    Dim i As Long
    Dim shP As Shape

    Set sh = Sheets("Sheet1")
    Set ws = Sheets("Sheet4")

    With sh
        Rws = .Cells(Rows.Count, "F").End(xlUp).Row
        Set Rng = .Range(.Cells(1, "F"), .Cells(Rws, "F"))
    End With

    With ws.Shapes
        i = .Count
    End With

    Set shP = ws.Shapes(i)

    shP.TextFrame.Characters.Text = Join(Application.Transpose(Rng), vbCrLf)

End Sub