I need to apply the following excel function as a macro. How could this be done?

I need it since it needs to be applied to over 60,000 cells and using VBA would go much faster. Copying the code by hand is too time consuming and inefficient.

=IF(D2="1",INDEX(Returns!$E$2:$P$34438,MATCH(A2&E1,Returns!$A$2:$A$34438&Returns!$D$2:$D$34438,0),12),INDEX(Returns!$E$2:$P$34438,MATCH(A2&E2,Returns!$A$2:$A$34438&Returns!$D$2:$D$34438,0),D2))

This formula is on the main ´Data1´ worksheet

A B C D E F
1 secid date rating Month Year Returns
2
3

It looks into a worksheet called Returns


A B C D E F
1 secid ICDI Ticker YEAR_R* Jan_RET Feb_RET Mar_RET etc.
2
3

Basically in the first sheet it checks for the secid, month and year. Then needs to find the secID in the second sheet which can appears on different rows due to different years, look in the proper row for the year of that particular secid and find the proper month accordingly.

Thank you so much!