macro index+Match+loop

hail11

Board Regular
Joined
May 3, 2007
Messages
199
dim name as string
for x = 1 to 5
name = Sheets("Main").Range("A"& x)
then i need INDEX([wss.xlsm]name!$AC$63:$AC$74,MATCH(C2,[wss.xlsm]name!$AB$63:$AB$74,FALSE),1)

for each sheet it is an associates name to get there pay and hours

I then need to copy this and paste it into

="Main!A"&x

Please help
 
Since you replied that you only need to place the found number in the Cell and not the formula, you could use INDIRECT in a temporary formula, then replace it with the resulting value.

Try...
Code:
Sub Lookup_PayData()
    Dim name As String
    Dim x As Long
    
    With Sheets("Main").Range("B1:B5")
        .FormulaR1C1 = "=INDEX(INDIRECT(""[wss.xlsm]"" & RC[-1]&""!$AC$63:$AC$74"")," _
        & "MATCH(R2C3,INDIRECT(""[wss.xlsm]"" & RC[-1]&""!$AB$63:$AB$74""),FALSE),1)"
        .Value = .Value
    End With
End Sub

I was trying it to move to a diffrent worksheet can i ask why this gives me a #REF in the cell now

Code:
Sub Lookup_hourswork()
    Dim name As String
    Dim x As Long
    
    With Sheets("Dates").Range("B123:B143")
        .FormulaR1C1 = "=INDEX(INDIRECT(""[David's Team 2011.xlsm]"" & RC[-1]&""!$B$10:$B$374"")," _
        & "MATCH(R122C2,INDIRECT(""[David's Team 2011.xlsm]"" & RC[-1]&""!$A$10:$A$374""),FALSE),1)"
        .Value = .Value
    End With
End Sub
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I was trying it to move to a diffrent worksheet can i ask why this gives me a #REF in the cell now

Is "David's Team 2011.xlsm" open when you run the macro?
It needs to be. (It would probably be a good idea to add a check that the file is open into the macro, or change to a formula that doesn't require the external reference file to be open).
 
Upvote 0
Just noticed one other thing that would need to change due to the reference to your new workbook.

Since the workbook reference has a space in it, you'll need to modify the formula to add single quotes around the
'[Work book]SheetName'

So the resulting reference looks like this...
='[David''s Team 2011.xlsm]Sheet1'!$B$10:$B$374

This wasn't needed when the workbook had no spaces...
=[wss.xlsm]Sheet1!$B$10!$B$10:$B$374
 
Upvote 0

Forum statistics

Threads
1,215,743
Messages
6,126,608
Members
449,321
Latest member
syzer

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