Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

internal pointer to external file reference

internal pointer to external file reference

internal pointer to external file reference

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.


RE: internal pointer to external file reference

It should be pretty straightforward, since VBA has lots of text manipulation functions.  You would take the value of A1, convert it to text and concatenate with the appropriate directory path and file extension, etc.


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). _
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!


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:

a2 then looks like this
OK, good, thats is what I want.

But I want my test cell looked like this:

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 I'm reading that correct, should be another concatenation:


or something to that effect


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,

RE: internal pointer to external file reference

OK, I see what you're doing.  The macro looks something like this:
Sub Macro1()
' Macro1 Macro
' Macro recorded 7/8/2002 by Eden Y.C. Mei
    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.


RE: internal pointer to external file reference

Oh, ignore the first 3 lines, they're a remnant of the macro recording.


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


RE: internal pointer to external file reference

Thanks, Both of you.
I'll give these things a try today.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close