0

需要帮助。我是 VBA 的新手,并试图从简单的宏开始。但即使失败得很惨。我要做的就是使用输入框从一个工作表复制并粘贴到另一个工作表以指定要复制的范围。现在我知道输入框是:

Application.InputBox("Enter the range from which you want to copy : ", Type:=8)

但是我需要什么行才能复制到另一个工作表中的单元格?

我提前为自己是个白痴道歉。

4

3 回答 3

2

这是你正在尝试的吗?

Option Explicit

Sub Sample()
    Dim rngCopyFrom As Range

    On Error Resume Next
    Set rngCopyFrom = Application.InputBox("Enter the range from which you want to copy", Type:=8)
    On Error GoTo 0

    If Not rngCopyFrom Is Nothing Then
        '~~> Copy the range to say Cell A1 of Sheets("weekly raw")
        rngCopyFrom.Copy ThisWorkbook.Sheets("weekly raw").Range("A1")
    End If
End Sub
于 2013-02-04T17:55:35.333 回答
1

一种方法是这样的:

Sub CopyRange()
    Dim FromRange As Range
    Dim ToRange As Range

    Set FromRange = Application.InputBox("Enter the range from which you want to copy : ", Type:=8)
    Set ToRange = Application.InputBox("Enter the range to where you want to copy : ", Type:=8)

    FromRange.Copy ToRange
    'Or you can do it like this if you need some flexibility on Paste 
    'FromRange.Copy
    'ToRange.PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
End Sub
于 2013-02-04T18:33:17.333 回答
0

这是一些示例代码:

Option Explicit

Sub CopyStuff()

Dim x As Range
Dim y As Range

Set x = Application.InputBox("Select what copy using the mouse", Type:=8)
Set y = ActiveWorkbook.Sheets("Sheet2").Range("A1")

x.Copy y

End Sub
于 2013-02-04T17:57:15.083 回答