Copy Named Ranges from One Workbook To Another

Anne Troy

MrExcel MVP
Joined
Feb 18, 2002
Messages
2,632
Office Version
  1. 365
Platform
  1. Windows
I'm pretty sure it's completely wrong, but here's what I've got:

Code:
Sub CopyToOAApp()

End Sub
Dim wbk As Workbook
Dim strFirstFile As String
Dim strSecondFile As String

strFirstFile = "wcs3.xlsm"
strSecondFile = "oaapp.xlsm"

Set wbk = Workbooks(strFirstFile)
With wbk.Sheets("Dashboard")
.Range("merchfirstname").Copy
.Range("merchconame").Copy
.Range("merchemail").Copy
.Range("repemail").Copy
End With
Set wbk = Workbooks.Open(strSecondFile)
With wbk.Sheets("Dashboard")
.Range("a:d").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With


End Sub

Those are the 4 named ranges I want to copy from wcs3.xlsm to oaapp.xlsm. The named ranges are the same in both workbooks. I copied someone's code, and began to alter it, but stalled on how to do the paste range. Theirs was, of course, a:d. I don't want the user to have to select any cells to get the data over.

Thanks tons for any help you can provide!
 
Code:
Dim oneName as Variant

For Each oneName in Array("merchFirstName","merchconame","merchmail","repemail")
    Workbooks("OAAp.xlsm").Names(oneName).RefersToRange.Value = Workbooks("wcs.xlsm").Names(oneName).RefersToRange.Value
Next oneName
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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