Copy paste data from one sheet to any other worksheet

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 06:59:42

问题


Hi there I have this code which only copy-paste data from sheet 1 one to sheet 2.

Sub CopyPasteCumUpdate()
    Dim rng As Range, inp As Range
    'to remove 0 values that may be a result of a formula or direct entry.
    Set rng = Nothing
    Set inp = Selection
    inp.Interior.ColorIndex = 37

    On Error Resume Next
    Set rng = Application.InputBox("Copy to", Type:=8)
    On Error GoTo 0

    If TypeName(rng) <> "Range" Then
        MsgBox "Cancelled", vbInformation
        Exit Sub
    Else
        rng.Parent.Activate
        rng.Select
        inp.Copy
        Worksheets("Sheet2").Paste Link:=True
        Application.CutCopyMode = 0
    End If
End Sub

Is it possible to input data and paste it to any other sheet without having to hard code?


回答1:


From your comment that is easy. Just change this part:

rng.Parent.Activate
rng.Select
inp.Copy
Worksheets("Sheet2").Paste Link:=True
Application.CutCopyMode = 0

With this:
Edit: This is to paste the link in the range the user selected.

Application.Goto rng
inp.Copy
rng.Parent.Paste Link:=True
Application.CutCopyMode = 0


来源:https://stackoverflow.com/questions/31801163/copy-paste-data-from-one-sheet-to-any-other-worksheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!