Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

excel - copy different sheet and make them one sheet

I have two sheet 1 and 2. in sheet 1 I have a button that browse a file and paste it in into the second sheet so I need help to be able to browse for the second sheet and be able to paste it under the first one that is already exist in sheet 2. I would appreciate your help

Sub hh()
'
' hh Macro
'

'
    Range("A1:A11").Select
    Selection.Copy
    Sheets("Sheet1").Select
    Range("B19").Select
    ActiveSheet.Paste
    ActiveWindow.SmallScroll Down:=9
    Sheets("Sheet2").Select
    Range("A2:A5").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Sheet1").Select
    Range("B30").Select
    ActiveSheet.Paste
End Sub

i recoded this code manually

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Note: This answer was for the original question with Sub hh which has since been edited out to create a new question

First of all your original code can be rewritten as:

Sub hh()

Sheets("Sheet2").Range("A1:A11").Copy
Sheets("Sheet1").Range("B19").Paste
Sheets("Sheet2").Range("A2:A5").Copy
Sheets("Sheet1").Range("B30").Paste

End Sub

Now you can modify the paste location based on the 'last row' which is what I believe you are asking. The last row would be found like this:

(comments in line)

Sub hh()

'Varible to store the last row in
Dim iLastRowSheet1 As Long

'copy initial data to memory
Sheets("Sheet2").Range("A1:A11").Copy

'find current last row
With Sheets("Sheet1")
    iLastRowSheet1 = .Range(B & .Rows.Count).End(xlUp).Row
End With

'paste using last row found + 1
Sheets("Sheet1").Range("B" & (iLastRowSheet1 + 1)).Paste

'repeat
Sheets("Sheet2").Range("A2:A5").Copy
With Sheets("Sheet1")
    iLastRowSheet1 = .Range(B & .Rows.Count).End(xlUp).Row
End With
Sheets("Sheet1").Range("B" & (iLastRowSheet1 + 1)).Paste

End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...