Question

I am trying to convert a text string into a formula, but my text string is a bit unusual because it describes a link between two worksheets. Here is the starting formula:

+TEXT("+'X:\Deals\ONE-PAGERS\_One-pagers (vM)\["&TRIM(LEFT(SUBSTITUTE($B9," ",REPT(" ",30)),64))&" vM.xlsx]Metrics'!$D$8",1)

I created this formula to avoid having to manually link a large number of spreadsheets. It captures the first two words of a cell, and places that into a text string that would establish a link, if it were a formula. This way, I can simply enter a company name into cell B9, and this formula will produce a text string that describes the link I want. Here is the formula output:

+'X:\Deals\ONE-PAGERS\_One-pagers (vM)\[xxx vM.xlsx]Metrics'!$D$8

As you can see, if this were a formula, it would generate a link it would return the value in Cell D8 of the xxx worksheet. I have tried the evaluate workaround (seen below) as well as the indirect function and neither seems to be working. Let me know if this doesn't make sense and thanks so much in advance for your help!

Function EvalCell(RefCell As String)
Application.Volatile
EvalCell = Evaluate(RefCell)
End Function
Was it helpful?

Solution

Evaluate and INDIRECT would both require the source workbook to be open, but you could use ExecuteExcel4Macro:

Function EvalCell(RefCell As String)
Application.Volatile True
application.ExecuteExcel4Macro(application.convertformula(mid$(RefCell, 2), xlA1, xlr1c1))
End Function

I'd avoid using too many of these functions though!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top