Translate an embedded Excel formula in vba for Excel

Jayem877

New Member
Joined
Oct 30, 2018
Messages
6
Hi,

I need help. I need to put this formula in Excel in vba code:

Code:
=IF(NETWORKDAYS(B4;B4)=0;0;IFERROR(INDEX(CS;MATCH(C4;CS_Position;0);MATCH(B4;CS_Date;1));IFERROR(INDEX(EC;MATCH(C4;EC_Position;0);MATCH(B4;EC_Date;1));IFERROR(INDEX(FI;MATCH(C4;FI_Position;0);MATCH(B4;FI_Date;1));IFERROR(INDEX(PA;MATCH(C4;PA_Position;0);MATCH(B4;PA_Date;1));IFERROR(INDEX(UTE;MATCH(C4;UTE_Position;0);MATCH(B4;UTE_Date;1));"Not found"))))))

Questions on my formula? Any ideas?

Thank you in advance!

Jayem
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You can use the macro recorder to get the formula in VBA code.

start recording macro, select cell with formula and select the formula box, hit enter, stop recording, look at the code.
 
Upvote 0
That is a pretty good idea, I should have thought about I. I'll try it tonight when I get home.

Thank you Dave!
 
Upvote 0
Hi Dave,

I don't think it worked. Here is what it gives:

Code:
 Range("D5").Select    ActiveCell.FormulaR1C1 = _
        "=IF(NETWORKDAYS(RC[-2],RC[-2])=0,0,IFERROR(INDEX(CS,MATCH(RC[-1],CS_Position,0),MATCH(RC[-2],CS_Date,1)),IFERROR(INDEX(EC,MATCH(RC[-1],EC_Position,0),MATCH(RC[-2],EC_Date,1)),IFERROR(INDEX(FI,MATCH(RC[-1],FI_Position,0),MATCH(RC[-2],FI_Date,1)),IFERROR(INDEX(PA,MATCH(RC[-1],PA_Position,0),MATCH(RC[-2],PA_Date,1)),IFERROR(INDEX(UTE,MATCH(RC[-1],UTE_Position,0),MATCH(" & _
        "RC[-2],UTE_Date,1)),""Not found""))))))"
    Range("D6").Select

It is ok I will change the "RC-2" with variables but it gives a syntax error.

Sorry I'm new to VBA... Hope you can help!
 
Upvote 0
You can simply use Evaluate and paste the formula as string like this:
Code:
Range("D5").value = Evaluate("[COLOR=#333333]=IF(NETWORKDAYS(B4;B4)=0;0;IFERROR(INDEX(CS;MATCH(C4;CS_Position;0);MATCH(B4;CS_Date;1));IFERROR(INDEX(EC;MATCH(C4;EC_Position;0);MATCH(B4;EC_Date;1));IFERROR(INDEX(FI;MATCH(C4;FI_Position;0);MATCH(B4;FI_Date;1));IFERROR(INDEX(PA;MATCH(C4;PA_Position;0);MATCH(B4;PA_Date;1));IFERROR(INDEX(UTE;MATCH(C4;UTE_Position;0);MATCH(B4;UTE_Date;1));"Not found"))))))")[/COLOR]

Just change the target range as you want, maybe a variable
 
Upvote 0
I have as a result a "#Value" but I think the evaluate function works well! Thank you AndyMachin for the tip!
 
Upvote 0

Forum statistics

Threads
1,215,385
Messages
6,124,626
Members
449,174
Latest member
Anniewonder

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