VBA copy past excel into existing sheet

I have the code below working, but it pastes the data into the wrong sheet.
The code should open a search box, where the user selects a file.
Then it copies the active sheet from that file, and pastes it into "Net Rates 1" sheet.
However, because the button to run is on the "Data Enter" sheet, THAT is where the copy/paste is going.

I tried to insert code to activate the Net Rates 1 sheet, but I continue to get errors when I try.
It's probably something so simple....
Can anyone help??

Sub ImportRate1()

Dim wb1 As Workbook
Dim wb2 As Workbook
Dim Sheet As Worksheet
Dim PasteStart As range

Set wb1 = ActiveWorkbook

Set PasteStart = range("A1")

Sheets("Net Rates 1").Select
    Cells.Select
    Selection.Delete


FileToOpen = Application.GetOpenFilename _
(title:="Please choose Net Rate Sheet 1", _
FileFilter:=".xls (*.xls),")

If FileToOpen = False Then
    MsgBox "No File Specified.", vbExclamation, "ERROR"
    Exit Sub
Else
    Set wb2 = Workbooks.Open(Filename:=FileToOpen)

    For Each Sheet In wb2.Sheets
        With Sheet.UsedRange
            .Copy PasteStart
            Set PasteStart = PasteStart.Offset(.Rows.Count)
        End With
    Next Sheet

End If

    wb2.Close

End Sub

Open in new window

Euro5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Try something like this.......

Delete the lines of code which are commented out in the below code and see if this resolves your issue.

Dim ws As Worksheet
Set wb1 = ActiveWorkbook
Set ws = wb1.Sheets("Net Rates 1")
Set PasteStart = ws.Range("A1")
ws.Cells.ClearContents
'Sheets("Net Rates 1").Select
'    Cells.Select
'    Selection.Delete

Open in new window

0
Euro5Author Commented:
@sktneer, that does the same but the existing sheet data is not removed.
0
Saurabh Singh TeotiaCommented:
Use this code..

Sub ImportRate1()

Dim wb1 As Workbook
Dim wb2 As Workbook
Dim Sheet As Worksheet, ws As Worksheet

Dim lr As Long


Set wb1 = ActiveWorkbook
Set ws = Sheets("Net Rates 1")
  ws.Cells.Delete

lr = 1
FileToOpen = Application.GetOpenFilename _
(title:="Please choose Net Rate Sheet 1", _
FileFilter:=".xls (*.xls),")

If FileToOpen = False Then
    MsgBox "No File Specified.", vbExclamation, "ERROR"
    Exit Sub
Else
    Set wb2 = Workbooks.Open(Filename:=FileToOpen)

    For Each Sheet In wb2.Sheets
        With Sheet.UsedRange
            .Copy ws.Range("a" & lr)
         lr = ws.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
        End With
    Next Sheet

End If

    wb2.Close

End Sub

Open in new window


Saurabh...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Euro5Author Commented:
Awesome! THANKS!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.