Help with making this code work

toddot04

New Member
Joined
Jul 1, 2015
Messages
13
Im trying to copy from one workbook to another. But I can't use workbook.name becuase the names keep changing. So to bypass that i created this and It almost works.

Sub Test()


Dim MR As Workbook
Dim Drun As Workbook
Dim myFileName As Variant
Dim SCR As Range, TGT As Range
Dim Inventory As Worksheet

Set Drun = ActiveWorkbook


myFileName = Application.GetOpenFilename
If myFileName = False Then
Exit Sub 'user hit cancel
End If


Set MR = Workbooks.Open(Filename:=myFileName)


Drun.Activate
Sheet3.Select


Range("A4:k20").Copy


MR.Activate
Worksheets("Inventory").Select

Range("a3").Paste <--- Runtime Error 438. Object does support this property



How can I optimize and fix this coding?
 
Last edited:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Fixed IT!!! Well that only took 4 days. Thanks for your help!



Sub Test()


Dim MR As Workbook
Dim Drun As Workbook
Dim myFileName As Variant
Dim SCR As Range, TGT As Range
Dim Inventory As Worksheet
Set Drun = ActiveWorkbook


myFileName = Application.GetOpenFilename
If myFileName = False Then
Exit Sub 'user hit cancel
End If


Set MR = Workbooks.Open(Filename:=myFileName)


Drun.Activate
Sheet3.Select


Range("A4:k20").Copy


MR.Activate
Worksheets("Inventory").Select


Range("a3").PasteSpecial


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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