Copy from another sheet, paste to current/active

JonathanK1

New Member
Joined
Mar 18, 2013
Messages
18
I need a macro that will copy data from another spreadsheet and paste it into the current spreadsheet (where the macro is stored). I'm working off of this (below). This opens up the other workbook (and appears to copy) but it's still pasting into a new workbook, which is not what I want.

Sub Button6_Click()
Dim TheAnswer As String
Set wb1 = Workbooks.opm (Filename:="blahblahblah.xlsm"
Dim working As Worksheet, dumping As Workbook
Set working = ActiveSheet
TheAnswer = LCase$(InputBox("Enter state below"))
Set dumping = Workbooks.Add
For x = 1 To 17
working.Rows(x).EntireRow.Copy
dumping.Activate
ActiveSheet.Paste <---------------------is this what needs to be changed???
ActiveCell.Offset(1).Select
Next
For x = 1 To working.Cells.SpecialCells(xlCellTypeLastCell).Row
If LCase$(working.Cells(x, 8).Value) = TheAnswer Then
working.Rows(x).EntireRow.Copy
dumping.Activate
ActiveSheet.Paste
ActiveCell.Offset(1).Select
End If
Next
Application.CutCopyMode = False
Cells.Sort Key1:=Range("C:C"), Order1:=xlAscending, _
Key2:=Range("Q:Q"), Order2:=xlDescending, Header:=xlYes
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi Jonathan -

At first glance, this is your issue. You're adding a new workbook here
Set dumping = Workbooks.Add
 
Upvote 0
Hi Keliyra,

Yes, I can see that now. I tried replacing the "Workbooks.Add" with "ActiveWorkbook" and a few other variations but nothing seems to be working. Do you have any idea what I would change it to? I tried removing it, but that created an error so it must be something I need to keep.

Sorry, I'm just learning about all of this macro stuff :P

I appreciate your help!

J-
 
Upvote 0
Sub Button6_Click()
Dim TheAnswer As String
Set wb1 = Workbooks.opm (Filename:="blahblahblah.xlsm"
Dim working As Worksheet, dumping As Worksheet
Set working = ActiveSheet
TheAnswer = LCase$(InputBox("Enter state below"))
Set dumping = Worksheet.Add
For x = 1 To 17
working.Rows(x).EntireRow.Copy
dumping.Activate
ActiveSheet.Paste
ActiveCell.Offset(1).Select
Next
For x = 1 To working.Cells.SpecialCells(xlCellTypeLastCell).Row
If LCase$(working.Cells(x, 8).Value) = TheAnswer Then
working.Rows(x).EntireRow.Copy
dumping.Activate
ActiveSheet.Paste
ActiveCell.Offset(1).Select
End If
Next
Application.CutCopyMode = False
Cells.Sort Key1:=Range("C:C"), Order1:=xlAscending, _
Key2:=Range("Q:Q"), Order2:=xlDescending, Header:=xlYes
End Sub

Try that - haven't had time to test so not 100% sure about it - but basically changes it from adding a new workbook to a new sheet in the current workbook.
 
Upvote 0

Forum statistics

Threads
1,203,078
Messages
6,053,402
Members
444,662
Latest member
AaronPMH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top