Macro Formula - Referencing by Declarations?!?!

Status
Not open for further replies.

ClimoC

Well-known Member
Joined
Aug 21, 2009
Messages
584
Hello,

I have this piece of code doing a sort of If/Lookup function between two workbooks.

Rich (BB code):
Sub boomerang()
Dim wb1 As Workbook
Dim master As Workbook
Dim sourcer As Range
Dim destr1, destr2, destr3, destr4 As Range
Dim c As Range
Dim r As Range
Dim ssheet As Worksheet
 
Set wb1 = ThisWorkbook
wb1.Activate
Set ssheet = ActiveSheet
    Set master = Workbooks("test.xls")
    If Err.Number > 0 Then Set master = Workbooks.Open(Filename:="Y:\DirPath\test.xls")
    If Not master Is Nothing Then master.Worksheets("Schedule").Activate Else MsgBox "File not found", vbInformation
master.Activate
Sheets("Schedule").Activate
Set destr1 = Range("AA6:AA500")
For Each c In destr1
        Cell.FormulaR1C1 = _
        "=IF(ISERROR(MATCH(1,(Book1.xls!$E$6:$E$100=I19)*(Book1.xls!$I$6:$I$100=N19)*(Book1.xls!$F$6:$F$100=J19),0)),"",INDEX(Book1.xls!$O$6:$O$100,MATCH(1,(Book1.xls!$E$6:$E$100=I19)*(Book1.xls!$I$6:$I$100=N19)*(Book1.xls!$F$6:$F$100=J19),0)))"
    Next
    
End Sub

For the bit in green , I need to be able to use the Declared workbooks "wb1" and "master" in this code. Reason being is that this module is exported to 15 different workbooks when they are created, so they all need to be able to figure out who they are, so that they may reference their own arrays instead of looking for "Book1.xls" which in all likelihood wouldn't exist.

Ps - it says "I19", "N19" because it's a sequential formula going in one whole column at the end of a table, and row 19 is just where I happened to copy the code from. Ideally, it should be looking at whatever row it happens to be in.

So can someone please quickly show me how to put in the wb1 and master in the formula so that in the reference are correct?

Cheers
C
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Status
Not open for further replies.

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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