# Thread: VBA Code for excel formula Thanks: 0 Likes: 0

1. ## VBA Code for excel formula

I have to include the below formula(IN BOLD) in a for loop of a vba code and compare with another cell with the same formula using IF ELSE Condition, but it keeps on throwing compile error.

=(VALUE(MID(A2,2,FIND(" ",A2)-2)))*IF(VALUE(MID(A2,SEARCH("through",A2)+8,1))>=4,4,VALUE(MID(A2,SEARCH("through",A2)+8,1)))

PFB the vba code i have written

ElseIf ( (VALUE(MID(x(10,j),2,FIND(" ",x(10,j))-2)))*( If (VALUE(MID(x(10,j),SEARCH("through",x(10,j))+8,1))) >= 4 Then 4 Else (VALUE(MID(x(10,j),SEARCH("through",x(10,j))+8,1)))) >

(VALUE(MID(Plan(x(4,j)& x(10,1)),2,FIND(" ",Plan(x(4,j)& x(10,1)))-2)))*( If(VALUE(MID(Plan(x(4,j)& x(10,1)),SEARCH("through",Plan(x(4,j)& x(10,1)))+8,1))) >= 4 Then 4 Else (VALUE(MID(Plan(x(4,j)& x(10,1)),SEARCH("through",Plan(x(4,j)& x(10,1)))+8,1)))))

Then wsCompetitor.Cells(10, j).Interior.Color = RGB(0, 255, 255)

2. ## Re: VBA Code for excel formula

Hello,

To get a VBA ' translation' of your formula ...

Just turn on your macro recorder and input the formula ...

Hope this will help