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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
Hi,

No need using Activate method.

Workbooks("wb2.xls").Sheets("Unpaid").Range("A1") =Workbooks("wb1.xls").Sheets("SDA").Range("mycell")

Suat
 
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,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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