VBA - replacing a workbook name with cell

Fredek

Board Regular
Joined
Mar 8, 2011
Messages
65
Hi, I would like to replace "EC_Rpt01Sep17 955.xlsm" with Cell N14 from Data tab in Credit Scoring.xlsm. Could someone give me a hint how to do this please?


Code:
Workbooks("Credit Scoring.xlsm").Worksheets("MGDataTbl").Range("A1:R323").Value = Workbooks[COLOR=#FF0000]("EC_Rpt01Sep17 955.xlsm")[/COLOR].Worksheets("MGDataTbl").Range("A1:R323").Value
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Give this a try:
Code:
    Dim wkbkName As String
    Windows("Credit Scoring.xlsm").Activate
    wkbkName = Sheet("Data").Range("N14")
    Workbooks("Credit Scoring.xlsm").Worksheets("MGDataTbl").Range("A1:R323").Value = Workbooks(wkbkName).Worksheets("MGDataTbl").Range("A1:R323").Value
 
Upvote 0
Thank Joe, I am getting a compile error: Sub or Function not defined , any idea what I'm missing?

Apologies, I am new to this! Thank you for your help.
 
Upvote 0
Sorry, had a minor typo. Should be:
Code:
    Dim wkbkName As String
    Windows("Credit Scoring.xlsm").Activate
    wkbkName = Sheet[COLOR=#ff0000][B]s[/B][/COLOR]("Data").Range("N14")
    Workbooks("Credit Scoring.xlsm").Worksheets("MGDataTbl").Range("A1:R323").Value = Workbooks(wkbkName).Worksheets("MGDataTbl").Range("A1:R323").Value
 
Upvote 0
I had a go with the new code and I get; Run time error 9, script out of range error.

For some reason it doesn't like it.
 
Upvote 0
It worked fine for me.

I suspect one of the following:
- bad file name
- bad sheet name
- protected or merged cells in the range you are trying to copy
 
Upvote 0
It worked fine for me.

I suspect one of the following:
- bad file name
- bad sheet name
- protected or merged cells in the range you are trying to copy

Hi Joe, I played around with it and it worked! Not sure what I was doing wrong at the start! Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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