VBA Code for excel formula


New Member
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)


Well-known Member

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

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

Hope this will help

Some videos you may like

This Week's Hot Topics