internal pointer to external file reference
internal pointer to external file reference
(OP)
I need help trying to find a way around this road block.
I want to create a cell, lets say (A1) with a year value, 2000, 2001, 2002 etc.
Later in the file I want to perform a test for a condition, and based on the results, retreive data from an external file of a given name and a tab name of the same value as (A1). There will be many additional tests similiar to this test throughout the sheet.
This file will be a template that we be used for many years, and I do not want to have to go through and change the file name or tab name at every single test cell on the sheet every time the year changes.
Maybe my whole approach here is wrong, if you have some better ideas I would like to hear them.
Thanks
I want to create a cell, lets say (A1) with a year value, 2000, 2001, 2002 etc.
Later in the file I want to perform a test for a condition, and based on the results, retreive data from an external file of a given name and a tab name of the same value as (A1). There will be many additional tests similiar to this test throughout the sheet.
This file will be a template that we be used for many years, and I do not want to have to go through and change the file name or tab name at every single test cell on the sheet every time the year changes.
Maybe my whole approach here is wrong, if you have some better ideas I would like to hear them.
Thanks
RE: internal pointer to external file reference
TTFN
RE: internal pointer to external file reference
You could write a macro (in "ThisWorkbook") to enter the year that the template is opened:
Private Sub Workbook_Open()
OpenDate = Date
Range("A1").Value = Year(OpenDate)
End Sub
Reading the data from another file is easily accomplished with a custom function if you know where in the sheet you want to read it from:
Function GetData(MyYear As String, Cell_Ref As String)
GetData = Workbooks(MyYear).Worksheets(MyYear). _
Range(Cell_Ref).Value
End Function
Note that the sheet you are reading from must be open for this function to work. If it is not open, you can open it automatically when the template is opened if you want (you can even open it hidden if you want).
I'm not sure how you reference the cells in the "Read" sheet, but the function I used above relies on a reference cell "Cell_Ref" that has something like "D1" typed into it. There are other ways to do the same thing, however.
Hope this helps!
jproj
RE: internal pointer to external file reference
That is exactly how I approached it but it would not work for me. My test cell looked something like this:
a1=2000
a2=concatenate("g:\somedir\[somefile]",a1,"deptrate")
a2 then looks like this
g:\somedir\[somefile]2000deptrate
OK, good, thats is what I want.
But I want my test cell looked like this:
=IF(c1=1,'g:\somedir\[somefile]2000deptrate'!g17)
How do I get the text string created by a2 in-between the single quotes in the line above?
Jproj, I'm not to familiar with macro's I'll give it a try.
Thanks, both, for your input.
RE: internal pointer to external file reference
=IF(c1=1,concatenate("'",concatenate("g:\somedir\[somefile]",a1,"deptrate")
,"'!g17")
or something to that effect
TTFN
RE: internal pointer to external file reference
That just dumps the results of the concatenation into the cell, it does not actually go out into the file and pull in the requested cell.
Good try,
Thanks
RE: internal pointer to external file reference
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/8/2002 by Eden Y.C. Mei
'
Range("A1").Select
Selection.Copy
Range("A2").Select
Range("A2").Value = "=[test" + Range("A1").Value + ".xls]sheet1!b3"
End Sub
and A1 in this case contains '2002, since that's the cheat for making sure that it's text and not a number. Sorry, I couldn't remember how to get the conversion.
TTFN
RE: internal pointer to external file reference
TTFN
RE: internal pointer to external file reference
To open the VBA editor, press Alt + F11 while in Excel. Next click on "Insert" and choose "Module". This will open a new module for your macro. Next, just paste the macro below into your module.
Sub GetData()
If Range("C1").Value = 1 Then
Range("A2").Value = "=" & Range("B2").Value
End If
End Sub
This will place a macro named "GetData" into you module. If you close the visual basic editor and go back to excel you can run the macro by pressing Alt + F8 (or by clicking on "Tools" and choosing "Macro" and "Macros...") The macro dialog box will pop up and you should be able to find the macro you just copied (GetData). Click on it and then click on "Run". The macro first checks for cell C1 = 1. If it is = 1 then the macro concantenates the equals sign with the contents of cell B2 and place the equation in cell A2. Cell A2 will then read the value of cell G17 of your read file. If Cell C1 is not = to 1, the macro does nothing.
You may also find it useful to use the "&" sign for concantenation instead of the equation:
="My" & "File" is the same as =CONCATENATE("My","File")
Hope this helps
jproj
RE: internal pointer to external file reference
I'll give these things a try today.
RF