VBA Vlookup from diffrent workbooks

Sotos13

New Member
Joined
Mar 8, 2019
Messages
42
hello everyone

i have a table that has multiple columns which each cell has this formula. It starts from D2 all the way down to D500
VLOOKUP($C2;'[Test1]Sheet1'!$A$2:$AI$137;4;0)*VLOOKUP($A2;'[Test2]Sheet1'!$A$3:$O$7927;2;0).

so it goes underneath VLOOKUP($C3 ...* VLOOKUP($A3...

In E2 i have the same formula but the only thing that changes is the column index fro both Vlookup
VLOOKUP($C2;'[Test1]Sheet1'!$A$2:$AI$137;6;0)*VLOOKUP($A2;'[Test2]Sheet1'!$A$3:$O$7927;3;0).

and
F2 the same with difrent col.index
VLOOKUP($C2;'[Test1]Sheet1'!$A$2:$AI$137;8;0)*VLOOKUP($A2;'[Test2]Sheet1'!$A$3:$O$7927;4;0).

So the first vlookup column index is changing in a step 2 manner and the second one adding one by one column.
this goes up to Q2
VLOOKUP($C2;'[Test1]Sheet1'!$A$2:$AI$137;30;0)*VLOOKUP($A2;'[Test2]Sheet1'!$A$3:$O$7927;15;0).

At the end in cell R2 i sum C2:Q2, R3 =sum C3:Q3..and so on.

What i want is a vba to calculate the above and just bring back the sum of this multiplication between those two vlookup.

Any ideas or any workarounds?
Thanks
 
Sub test()
Third = ActiveWorkbook.Name




Workbooks("First").Activate
' note I load the array from A1 to make the indexing simpler
Firstarray = Worksheets("Sheet1").Range("$A$1:$AI$137")
Workbooks("Second").Activate
' ditto
SecondArray = Worksheets("Sheet1").Range("$A$1:$O$7927")
Workbooks("Third").Activate
Searcharr = Range("A1:C500")
For i = 2 To 500
For j = 2 To 137
If Searcharr(i, 3) = Firstarray(j, 1) Then
' found the first index
For k = 1 To 7927
If Searcharr(i, 1) = SecondArray(k, 1) Then
' found the second index
' so do the calculatiosn here
' this just does the first equation on your line but the others are very similar
Cells(i, 4) = Firstarray(j, 4) * SecondArray(k, 2)
End If
Next k
End If
Next j
Next i
End Sub
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
A quick bit a googling came up with a possible answer try adding the extension to the workbooks line:
Code:
[COLOR=#333333]Workbooks("First.xlsx").Activate[/COLOR]
or whatever the ext is for your file
 
Upvote 0
A quick bit a googling came up with a possible answer try adding the extension to the workbooks line:
Code:
[COLOR=#333333]Workbooks("First.xlsx").Activate[/COLOR]
or whatever the ext is for your file

I found that as well, and i tried it but noooo..it didn't work.
Did you try it with the data that i sent you?
Are you able to execute it or no.
 
Upvote 0
the data in the workbook doesn't matter , I can load data from a remote workbook quite happily , I have done it many times. I don't know what is different about your set up.
 
Upvote 0
What version of Excel are you running ,what operating system. are the files stored locally or on aremote drive?
What line of your code is the error on and what is the error
 
Upvote 0
hi again,

i added all the sheets in one workbook and i changed the code. iget a result but i also get the same error. can you try it ?

Sub test()


Third = ActiveWorkbook.Name


Workbooks("Third").Activate


Searcharr = Worksheets("Sheet1").Range("A2:C23")
Firstarray = Worksheets("Sheet2").Range("$A$1:$G$22")
SecondArray = Worksheets("Sheet3").Range("$A$1:$E$24")

For i = 2 To 23
For j = 2 To 22
If Searcharr(i, 3) = Firstarray(j, 1) Then
Debug.Print
' found the first index
For k = 1 To 24
If Searcharr(i, 1) = SecondArray(k, 1) Then
' found the second index
' so do the calculatiosn here
' this just does the first equation on your line but the others are very similar
Cells(i, 4) = Firstarray(j, 4) + SecondArray(k, 2)
End If
Next k
End If
Next j
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,324
Messages
6,124,250
Members
449,149
Latest member
mwdbActuary

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