Hi,everyone, can any help me? what's wrong with this VBA code?

yeongkwe

New Member
Joined
Dec 13, 2016
Messages
13
Hi, I would like to create a VBA code as I counter problem when the code to jump into another workbooks to select the range and I encounter this problem, this box come out stated "run-time error 1004 select method of range class failed" Can any nice smart people here kindly help me and tell me what's had I done wrong. Thanks. The code is below.


Sub Testing()



Workbooks("Date check").Worksheets("sheet3").Range("A1:F5").Copy Workbooks("New improved 4D JAN 20 2017 3 Mar with new add in method Gtotal and Y big count with micro").Worksheets("sheet1").Range("A97997")

Workbooks("New improved 4D JAN 20 2017 3 Mar with new add in method Gtotal and Y big count with micro").Worksheets("sheet1").Range("F97996:H97996").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("F97996:H98001"), Type:=xlFillDefault
Range("F97996:H97997").Select
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
yeongkwe,

Not sure why you are pasting values at the range you are, or selecting the range you are. But the below code copies and pastes to the defined workbooks. Make sure the extensions match also.

Code:
copyWB = Workbooks("Date check.xlsm").Name
pasteWB = Workbooks("New improved 4D JAN 20 2017 3 Mar with new add in method Gtotal and Y big count with micro.xlsm").Name

Workbooks(copyWB).Worksheets("Sheet3").Range("A1:F5").Copy Destination:=Workbooks(pasteWB).Worksheets("Sheet1").Range("A97997")

Workbooks(pasteWB).Worksheets("Sheet1").Range("F97996:H97996").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("F97996:H98001"), Type:=xlFillDefault

Let me know if this is what you were looking for.

Bill
 
Upvote 0
Hi, sorry to disturb you again, I can't even go thru the first code this rime, copyWB = Workbooks("Date check.xlsm").Name as error box come out "run-time error 9 subscript out of range.




Not sure why you are pasting values at the range you are, or selecting the range you are. But the below code copies and pastes to the defined workbooks. Make sure the extensions match also.

Code:
copyWB = Workbooks("Date check.xlsm").Name
pasteWB = Workbooks("New improved 4D JAN 20 2017 3 Mar with new add in method Gtotal and Y big count with micro.xlsm").Name

Workbooks(copyWB).Worksheets("Sheet3").Range("A1:F5").Copy Destination:=Workbooks(pasteWB).Worksheets("Sheet1").Range("A97997")

Workbooks(pasteWB).Worksheets("Sheet1").Range("F97996:H97996").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("F97996:H98001"), Type:=xlFillDefault

Let me know if this is what you were looking for.

Bill[/QUOTE]
 
Upvote 0
Make sure the extension of the workbooks match (e.g. xlsm, xlsx, etc.)

Code:
copyWB = Workbooks("Date check.[B]xlsm[/B]").Name
 
Last edited:
Upvote 0
Hi, I had I remove the .xlsm and it works again, But the same problem still happen when come to this line of code Workbooks(pasteWB).Worksheets("Sheet1").Range("F97996:H97996").Select


Sub testing()


copyWB = Workbooks("Date check").Name
pasteWB = Workbooks("New improved 4D JAN 20 2017 3 Mar with new add in method Gtotal and Y big count with micro").Name

Workbooks(copyWB).Worksheets("Sheet3").Range("A1:F5").Copy Destination:=Workbooks(pasteWB).Worksheets("Sheet1").Range("A97997")

Workbooks(pasteWB).Worksheets("Sheet1").Range("F97996:H97996").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("F97996:H98001"), Type:=xlFillDefault


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,853
Members
449,051
Latest member
excelquestion515

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