spreadsheet Links

Peter100

Well-known Member
Joined
Apr 21, 2002
Messages
765
I have a workbook named Master.xls which is a master template.
I have workbooks for each month named JanData.xls - Dec.xls

I want to link the data from cell A1 in JanData.xls into cell A1 of
Master.xls which is simple enough.

The link would look like ='[JanData.xls]Sheet1'!$A$1

But what I want to be able to do is replace the [JanData.xls] part of the link
with a cell reference in Master.xls which would be a text entry so that the link
could be changed to read from FebData.xls - MarData.xls etc as desired.

Anyone any Ideas ?
 
Hi Tom

going back to your first comment, my problem is in creating the link in the first place not changing the reference.

re your recent comment; there are not any $ references relevant to the data reading range.

Please have a look at Chris's formula
=INDIRECT("["&$A$1&"Data.xls]Sheet1!"&ADDRESS(1,COLUMN(A:A),4,1))
and comment if you can
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I can't comment on the formula. I know very little about functions and formulas just yet.
Sorry.
I was under the impression that your links were already setup and you wanted an easy way to change them for a new month???
If your entire master workbook is refering to FebData.xls then the macro would go through every sheet and replace Feb with Mar.
Tom
 
Upvote 0
Sorry Peter,

I overlooked the "1" that was anchoring the row number

try :

=INDIRECT("["&$A$1&"Data.xls]Sheet1!"&ADDRESS(row(),COLUMN(A:A),4,1))



_________________
Hope this helps,
Chris
(Excel '97, Windows ME)

Edit : I should add that there's a couple of volatile fucntions there which may slow your workbook down and swell its size detrimentally. Please try those VBA solutions which may well be more desireable.
This message was edited by Chris Davison on 2002-05-13 06:06
 
Upvote 0
CHRIS YOU ARE A GENIUS

Haven't encountered the problems you mentioed yet but will bear it in mind.

If you are still game, how about really making it rock & roll.

Assuming cell A1 contains "Jan" (no quotes) and cell A1 has data validation selecting from a list of Jan Feb Mar etc.

how can we make the workbook upon being opened automatically open xxx.data.xls where xxx is the text in Sheet 1, cell A1. Then when the value of A1 is changed open the relevant xxx.data.xls workbook.
 
Upvote 0
On 2002-05-13 07:08, Peter100 wrote:
CHRIS YOU ARE A GENIUS

Haven't encountered the problems you mentioed yet but will bear it in mind.

If you are still game, how about really making it rock & roll.

Assuming cell A1 contains "Jan" (no quotes) and cell A1 has data validation selecting from a list of Jan Feb Mar etc.

how can we make the workbook upon being opened automatically open xxx.data.xls where xxx is the text in Sheet 1, cell A1. Then when the value of A1 is changed open the relevant xxx.data.xls workbook.

ahh, yes, ermmm, physically opening a file based on a cell content needs some VBA coding
, and this means a different type of genius....

Maybe Tom can help if he's keeping an eye on this thread....

:)

(I see why you ask though, INDIRECT won't work with closed workbooks...)



_________________
Hope this helps,
Chris
(Excel '97, Windows ME)


edit : you could pop a hyperlink next to the dropdown cell if you want.... in which case, Yogi's earlier suggestions would work perfectly.... have a play around and see what you can come up with
This message was edited by Chris Davison on 2002-05-13 08:05
 
Upvote 0
You can make Chris' formula work with closed workbooks by supplying a filepath:

=INDIRECT("'c:temp["&$A$1&"Data.xls]Sheet1'!"&ADDRESS(1,COLUMN(A:A),4,1))

Which isn't a bad idea.

In Tom's absence, I'll give you an event procedure to open the file, where B1 holds one of your formulae. Change all [B1] instances to an address that holds the formula if necessary (e.g., [b1] to [c4])

Right-click on the sheet in question, click 'view code' and paste the following code.<pre>
Private Sub Worksheet_Change(ByVal Target As Range)
'macro recorded by Nate
Dim n As Integer, p As String, o As Integer, s As Integer
Dim z As String
If Target.Address = "$A$1" Then
n = InStr([b1].Formula, ":")
p = Mid([b1].Formula, n - 1, 1)
o = InStr([b1].Formula, "[")
s = InStr([b1].Formula, "]")
ChDrive (p)
ChDir Mid([b1].Formula, n - 1, (o - (n - 1)))
z = Application.Substitute(Mid([b1].Formula, _
o + 1, s - 1 - o), ".xls", "") & ".xls"
Workbooks.Open [a1].Value & Application.Substitute(z, _
"""&$A$1&""", "")
End If
End Sub</pre><pre></pre>
You should be set.

Chris get's the MVP nod. Nice work :), notice a few got called up.


Edit: When I post with BB, $A$1 is being truncated to $A erroneously. Having [big] trouble with BB as of late.
_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
wave.gif

This message was edited by NateO on 2002-05-13 10:51
 
Upvote 0
On 2002-05-13 09:30, NateO wrote:
You can make Chris' formula work with closed workbooks by supplying a filepath:

=INDIRECT("c:temp 2002-05-13 09:34 ]</font>

interesting ! I shall have a tinker with this toute de suite :)

thanks Nate
 
Upvote 0
You'll need to insert single ""'s where appropriate. They got crushed during my edit.

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
wave.gif

This message was edited by NateO on 2002-05-13 09:42
 
Upvote 0
Alrighty. The indirect doesn't like the path (doesn't mind it if the file's open, but isn't responsive when closed, defeating the purpose), which the code above is based on, so I'm going to rephrase this.

If you use an indirect formula method, the target file has to be open. To open the file with a vba procedure, use the following code with Chris' formula. Right-click on the sheet with your Data Validation list, click 'view code' and paste the following code:<pre>
Private Sub Worksheet_Change(ByVal Target As Range)
'Macro recorded by Nate
Dim o As Integer, s As Integer
Dim z As String
If Target.Address = "$A$1" Then
o = InStr([b1].Formula, "[")
s = InStr([b1].Formula, "]")
ChDrive ("C") 'hardcode your target drive letter
ChDir ("C:tempxltest") 'hardcode your target file path
z = Application.Substitute(Mid([b1].Formula, _
o + 1, s - 1 - o), ".xls", "") & ".xls"
Workbooks.Open [a1].Value & Application.Substitute(z, _
"""&$A$1&""", "")
End If
End Sub</pre>

However, you can set this up with a pure vba solution that will allow you to update your information without having to open the target workbook.

Setting up the link is the easy part. Open your master file and one of the monthly files (e.g., JanData.xls). Now in the master click +, then move to the JanData.xls, click on the cell of choice file and press enter. You've now established your link. Remove the $ signs to remove absolute addressing.

Now, if you right click on the sheet with your validation list, click view code, paste the following code in:<pre>
Private Sub Worksheet_Change(ByVal Target As Range)
'Macro recorded by Nate
Dim Worksheet As Worksheet, cl As Range, frm As String
Dim z As String, o As Integer, s As Integer, FrmCls As Range
If Target.Address = "$A$1" Then
For Each Worksheet In ThisWorkbook.Worksheets
Set FrmCls = Nothing
On Error Resume Next
Set FrmCls = Worksheet.[a1].SpecialCells(xlFormulas)
If FrmCls Is Nothing Then GoTo 1
For Each cl In FrmCls
frm = cl.Formula
If InStr(frm, "[") Then
o = InStr(cl.Formula, "[")
s = InStr(cl.Formula, "]")
z = Mid(cl.Formula, o + 1, s - o)
cl.Replace What:=z, Replacement:=[a1].Value & "Data.xls]", _
MatchCase:=False, lookat:=xlPart
End If
Next cl
1:
Next Worksheet
End If
End Sub</pre>

If you change Jan to Feb in cell a1, every link your workbook that had JanData.xls will be updated to FebData.xls

However you want to work it, I think the 2nd's a little easier to handle from an end-user perspective.

Hope this helps.

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
wave.gif

This message was edited by NateO on 2002-05-13 14:21
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top