Copy from workbook 2 and paste to wb1 range

simmerer

New Member
Joined
Sep 6, 2017
Messages
33
Hi,.
I have this and it fails at the paste for "Subscript out of range". It would seem I am not properly selecting my destination. Is it my method?

Sub Macro2()
'
' Macro2 Macro
Dim wb1 As Excel.Workbook 'Open PSSLA workbook first
Set wb1 = ThisWorkbook
Dim wb2 As String 'Open Raw Data Workbook next
wb2 = Application.GetOpenFilename("Excel workbooks,*.xls*")

If wb2 = "False" Then
' ' the user clicked Cancel

Else
' the user selected a file; its path+name is in wb2
Application.Workbooks.Open Filename:=wb2
End If

Worksheets("IBM Rational ClearQuest Web").Range("A2:K2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("wb1").Worksheets("PS").Select (failure point)
Range("A2").Select
Selection.Paste

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Re: Copy from woorkbook 2 and paste to wb1 range

Try
Code:
wb1.Worksheets("PS").Select
 
Last edited:
Upvote 0
Re: Copy from woorkbook 2 and paste to wb1 range

Try

wb1.Worksheets("PS").Select
 
Last edited:
Upvote 0
Re: Copy from woorkbook 2 and paste to wb1 range

Hi Fluff! Thanks for responding. I have already tried your suggestion and I get the same error. It is like the code forgot what wb1 was.
 
Upvote 0
Re: Copy from woorkbook 2 and paste to wb1 range

Sorry it should be
Code:
wb1.Worksheets("PS").Activate
 
Upvote 0
Re: Copy from woorkbook 2 and paste to wb1 range

Do you have a sheet in ThisWorkbook called PS?
 
Upvote 0
Re: Copy from woorkbook 2 and paste to wb1 range

Yes, I have a worksheet named "PS" in ThisWorkbook. I start with my first workbook open. Rather than use the qualified file name (which changes monthly), i just refer to it as ThisWorkbook, then assign the wb1. Thisworkbook value can change, so I didn't want to use it any further.
 
Upvote 0
Re: Copy from woorkbook 2 and paste to wb1 range

Thisworkbook is the workbook containing the macro. Is that the workbook that contains the "PS" sheet?
 
Upvote 0
Re: Copy from woorkbook 2 and paste to wb1 range

Actually the macro is in my Personal workbook which I have hidden.
 
Upvote 0

Forum statistics

Threads
1,223,710
Messages
6,174,019
Members
452,542
Latest member
Bricklin

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