We help IT Professionals succeed at work.

VBA : replace a variable based on cell value

Hello experts,

I used the following expressions in one of my VBA code:

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\path\file.csv", 

 With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\path\file2.csv", 

Open in new window


I will like to replace C:\path\ by the value of Sheet1.Range(A2).Value


Instead of having directly the path within the code I will like to set up a variable based on the
Sheet1.Range(A2).Value

Something like this :
Set PATH2=Sheet1.Range(A2).Value

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;&PATH2&file.csv", 

 With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;&PATH2&file2.csv", 

Open in new window


I don't exactly how should I set up this variable.
Thank you in advance for your help.
Comment
Watch Question

Try this...

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;" & Sheet1.Range(A2).Value & "file.csv", 

 With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;" & Sheet1.Range(A2).Value & "file2.csv", 

Open in new window