Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

link in excel formula

Status
Not open for further replies.

bultimatem

Programmer
Jun 9, 2003
13
US
I am having a problem inserting a filepath in a formula. There is some really nasty splitting going on.

In VBA I am inserting a formula in a cell in the form:
=someStuff, someotherstuff,LOOKUP(range1,[C:\somefolder\someWorkbook.xls]someSheet!Range2,[C:\somefolder\someWorkbook.xls]someSheet!Range3)

In VBA for the file path name, I'm using Application.Workbooks(someWorkbook.Name).FullName

so my code looks like:
Dim filePath as string
filePath = Application.Workbooks(neededWorkbook.Name).FullName
Dim theSheet as worksheet
set theSheet = neededWorkbook.Sheets("someSheet")
Dim Rg2 as range, Rg3 as range
set Rg2 = theSheet.Range("Range2")
set Rg3 = theSheet.Range("Range3")

Dim theFormula as string

theFormula = "=somestuff, someotherstuff, LOOKUP(range1," _
" '[" & filePath & "]" & theSheet.Name & "'!" & Rg2.Name ...

the problem is that the actual formula entered in the activecell is:

= somestuff, someotherstuff, LOOKUP(range1, 'C:\somefolder [C:\somefolder\someWorkbook.xls]someSheet'!Range3 ...

I have no idea why it's splitting up that file path like that. I realize that there needs to be single quotes because there is the possibility of being folders with embedded spaces. This is the only set up of the single quotes that doesn't give me an error. I've read that there often needs to be two single quotes at the beginning (''[C:\..]sheet'!range) but I tried that and I received an error every time it tried to enter it in the cell.

Any ideas? Thanks in advance


Bryan Marble
IEWS
BAE Systems
 
Just as added info, I need to choose the sheet because the range isn't specific to one sheet.

Bryan Marble
IEWS
BAE Systems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top