VBA INDEX and MATCH with 2 different tables

_Chanty_

New Member
Joined
Oct 10, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have 2 tables named FDT_Previous and FDT_1. I want to retreive the hours in column FDT_1 [8/18/24] the hours from column FDT_Previous [8/18/24] where "employee number" "task code" are the same.

The formula in my column FDT_1 [8/18/24] is working perfectly :
=IFERROR(INDEX(FDT_Previous[8/18/24], MATCH(1, (FDT_Previous[employee number] = [@[employee number]]) * (FDT_Previous[task code] = [@[task code]]), 0)), "")
1728560817614.png


When I'm doing this code in the VBA :

ActiveCell.FormulaR1C1 = "=IFERROR(INDEX(FDT_previous[" & Prev_dimanche & "], MATCH(1, (FDT_previous[employee number] = [@[employee number]]) * (FDT_previous[task code] = [@[task code]]), 0)), """")"

The result is :
=IFERROR(INDEX(FDT_Previous[8/18/24], MATCH(1, (FDT_Previous[@[employee number]] = [@[employee number]]) * (FDT_Previous[@[task code]] = [@[task code]]), 0)), "")

That's mean the formula is incorrect. It change my reference column into cell reference and it's not appropriate.

I tried multiple approaches with the same failed result.

How can I resolve this ?

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi and welcome to MrExcel !

Try:

VBA Code:
Sub Macro_Index_Match()
  With Range("FDT_1[18/08/2024]")
    .FormulaR1C1 = _
        "=INDEX(FDT_Previous[[13/08/2024]:[18/08/2024]],MATCH([@Emp],FDT_Previous[Emp],0),MATCH(FDT_1[[#Headers],[18/08/2024]],FDT_Previous[[#Headers],[13/08/2024]:[18/08/2024]],0))"
  End With
End Sub

If you want only the values:

VBA Code:
Sub Macro_Index_Match()
  With Range("FDT_1[18/08/2024]")
    .FormulaR1C1 = _
        "=INDEX(FDT_Previous[[13/08/2024]:[18/08/2024]],MATCH([@Emp],FDT_Previous[Emp],0),MATCH(FDT_1[[#Headers],[18/08/2024]],FDT_Previous[[#Headers],[13/08/2024]:[18/08/2024]],0))"
    .Value = .Value
  End With
End Sub

🤗
 
Upvote 0
Hi and thanks for your welcome,

This code works after I adjust the header names :

Sub Macro_Index_Match()
With Range("FDT_1[8/18/24]")
.FormulaR1C1 = _
"=INDEX(FDT_Previous[[task code]:[8/18/24]],MATCH([@employee number],FDT_Previous[employee number],0), " & _
"MATCH(FDT_1[[#Headers],[8/18/24]],FDT_Previous[[#Headers],[task code]:[8/18/24]],0))"
End With
End Sub


Therefore, this formula miss the part where I need to match the task code as well.
(FDT_previous[task code] = [@[task code]])

Can you adjust it ?

Thanks
 
Upvote 0

Forum statistics

Threads
1,222,580
Messages
6,166,880
Members
452,080
Latest member
Akin Himself

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