Another Macro and linking question

kluitna

Board Regular
Joined
Mar 10, 2002
Messages
75
Thanks to all who have helped me so far. I have 2 quick questions.

I have the current code as follows:
Sub test()
Dim Source As String
Dim Path As String
Dim sht As String
Path = Worksheets("List").Cells(1, 1)
For i = 0 To 500
Source = Worksheets("list").Cells(2 + i, 1)
ChDir Path
Workbooks.Open FileName:=Source
Windows("Estimate Summary.xls").Activate
Worksheets("ITEMS").Select
Worksheets("ITEMS").Cells(6 + i, 1).Select
strfile = Source
ActiveCell.FormulaR1C1 = "='" & strfile & "'!R9C3"
If Source = blank Then End
Next
End Sub
And it works fine, what I can't figure out is how to get the a variable for every given worksheeet in the workbook soucre. As you can tell Souce just refereces a cell in the current worksheet that is a name of a workbook with souce information. Each souce workworrk has 30 worksheets in it. The above works great in getting to the first worksheet. Then it stops. Any sugestions out there?

Also is there a way to go into workbooks and disassociate all the old links? I have kind of made a mess of some sheets experimenting with these macros linking them together. When I am done I don't want a bunch of bogus links lurking out there.

Thanks in advance, this forum is a great resouce.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I haven't tested this code, but it should work:
Sub test()
Dim Source As String
Dim Path As String
Dim NumSheets As Long
Dim SheetName As String
NumSheets = ThisWorkbook.Worksheets.Count
For h = 1 To NumSheets
SheetName = ThisWorkbook.Worksheets(h).Name
Path = Worksheets(SheetName).Cells(1, 1)
For i = 0 To 500
Source = Worksheets(SheetName).Cells(2 + i, 1)
ChDir Path
Workbooks.Open Filename:=Source
Windows("Estimate Summary.xls").Activate
Worksheets(SheetName).Select
Worksheets(SheetName).Cells(6 + i, 1).Select
strfile = Source
ActiveCell.FormulaR1C1 = "='" & strfile & "'!R9C3"
If Source = blank Then End
Next
Next h
End Sub

Hope this helps.
Kind regards, Al.
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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