How to copy selection.address cell values to another workbook.?

miqbal

New Member
Joined
Mar 7, 2018
Messages
11
hi,
I am new to VBA and tryin to reduce some workload to make a small VBA program to copy range randomly with mouse and paste it to destination file.
source file is "Mytest.xlsm" and destination file is "BatchEntry.xlsx"

I can easily copy range by below code and successfully paste It to other sheet but when I tried to paste it to another workbook it gives me error.

so below is the code I ran it in source file which is "Mytest.xlsm"

Sub copytoBatchEntry()

Set areatocopy = Sheet1.Range(Selection.Address)
areatocopy.Copy

'sheet2.range("a2").PasteSpecial ---- it works without any error for current workbook's worksheet.

Workbooks.Open ("U:\Batch Entry.xlsx")
Windows("Batch Entry.xlsx").Activate

Windows("Batch Entry.xlsx").Sheets("sheet1").Range("a2").PasteSpecial
End Sub


the above code gives error
"Run Time Error: 438 object doesn't support this property or method."

Please if someone can help to point out what I am doing wrong here.
 
Welcome.
But if you want the format in the selected cell to be copied (for example background colour or Font Style etc.,) then you may have to edit this code...
Code:
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
as this ...
Code:
 Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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