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 to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
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
 

smozgur

BatCoder
Joined
Feb 28, 2002
Messages
1,580
Hi,

No need using Activate method.

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

Suat
 

pilot

Active Member
Joined
Feb 17, 2002
Messages
345
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.
 

Forum statistics

Threads
1,147,622
Messages
5,742,199
Members
423,711
Latest member
luisfreitas

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
Top