VBA - Using a String value in formula

CeReaLK

New Member
Joined
Jul 3, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I am prety new to VBA and i was wondering if its possible to use a String as part of a formula like the example below.

Sub Test()

Dim IT_FR_IT_Rate As String
IT_FR_IT_Rate = Range("A1").Value - A1 containts the excel file name Filename.xslx.
Range("A2").Select
ActiveCell.Formula = _
"=INDEX('C:\Path\path2\""& IT_FR_IT_Rate &""'!Target_EUR_Difd,1,0)"
End Sub

If not, how could i make this work. The file name should be stored in a cell, so that it can be easily changed.
Note that the destination excel file is closed.

Thank you in advance.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi & welcome to MrExcel.
What is Target_EUR_Difd ?
 
Upvote 0
Hello,
its a named range located in the target file..
The above is just a part of the whole formula. The original formula contains more Indexes/matches to the same target file.
Thats why i used only a part.
 
Upvote 0
In that case try
VBA Code:
Dim IT_FR_IT_Rate As String
IT_FR_IT_Rate = Range("A1").Value
Range("A2").Formula = _
   "=INDEX('C:\Path\Path2\" & IT_FR_IT_Rate & "'!Target_EUR_Difd,1,0)"
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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