How to pass named range in vba

pilot

Active Member
Joined
Feb 17, 2002
Messages
345
I posted a similar question yesterday and got no takers. With wb1 and wb2 open, wb2 is active, I want vb code to place a named cell from wb1 into A1 of wb2. I found a way that works (below) but I'm sure it's not the cleanest approach.

Windows("wb1.xls").Activate
mycell = ActiveWorkbook.Sheets("SDA").Range("mycell")
Windows("wb2.xls").Activate
ActiveWorkbook.Sheets("Unpaid").Range("A1") = mycell
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi Pilot,

How about something like this:<pre>
Sub copyit()

Workbooks("wb1.xls").Worksheets("SDA").Range("mycell").Copy _
Destination:=Workbooks("wb2.xls").Worksheets("Unpaid").Range("A1")

End Sub</pre>
HTH

EDIT: Changed sheet names to OP's sheet names.
PS. I seem to remember reading somewhere that it is quicker not to copy&paste. I suggest you use Smozgur's solution (see below).
_________________<font color="blue"> «««<font color="red">¤<font color="blue"><font size=+1>Richie</font><font color="red">¤<font color="blue"> »»»</font>

caffeine_sample.gif
</gif>
This message was edited by Richie(UK) on 2002-08-29 05:53
 
Upvote 0
Thanks, both of you. I knew it was elementary, I just couldn't get all the language just right. I really need to get a good book on VBA.
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

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