Copying dynamic named ranges to different workbooks

getafix40

New Member
Joined
Aug 1, 2014
Messages
49
Hi

I need to copy and paste a formula (highlighted in bold) to all the .xlsm files in a specific directory. The process works but I am getting a #NAME? error.

The dynamic name ranges refer to a workbook called Figure the deal2.xslm

Private Sub CommandButton1_Click()


MyDir = ActiveWorkbook.Path
DataDir = MyDir & "\Job Cards\"
ChDir (DataDir)
Nextfile = Dir("*.xlsm")
While Nextfile <> ""
Workbooks.Open (Nextfile), WriteResPassword:="*********"
Workbooks(Nextfile).Sheets("Sheet1").Range("c5") = "=VLOOKUP($I$4,Table,MATCH('[Figure the deal2.xlsm]StockSheet'!B$1,ColumnLabel,0),FALSE)"
Workbooks(Nextfile).Save
Workbooks(Nextfile).Close
Nextfile = Dir()
Wend

End Sub

Any ideas how to get it to work?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
It would throw a #NAME error if either Table or ColumnLabel were not defined names in the workbook.
There may be other explanations that I've missed.

/AJ
 
Upvote 0
It would throw a #NAME error if either Table or ColumnLabel were not defined names in the workbook.
There may be other explanations that I've missed.

/AJ

I thought the same as the named ranges refer to a different work book (figure the deal2.xlsm) How do I copy the named ranges to each file (workbook)

I created a template file with all the correct named ranges and when I save file saves as it works.

The above script will go through all the files and make the necessary changes automatically - will save me loads of time.
 
Upvote 0

Forum statistics

Threads
1,225,482
Messages
6,185,253
Members
453,283
Latest member
Shortm88

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