Hello,

I am new to VBA and my approach is usually through trial and error and hope that it will work.

Unfortunately this time I am stuck and I hope you could help me.


I have created formula as below in cell H3:

'=IF((IF(OR(C3=0;B3=0;D3=0;E3=0;F3<=0);0;A4- A3))<0;0;IF(OR(C3=0;B3=0;D3=0;E3=0;F3<=0);0;A4-A3))

Then I have double clicked and the formula was copied down the column.
Calculations were performed within 10min and I got what I wanted.


I have read that using VBA to perform calculations will speed up calculations.
I have created macro as below which works on small number of cells but for the large number of rows it takes too much time.

I have estimated that the same calculations as above in my case with the loop will take 12h.

Can you please have a look and let me know what I am doing wrong?
I presume the problem is with the “or” function.

I am looking forward for any suggestions.

Flooyd

Sub test()

Worksheets("Sheet2").Activate
i = 3
 Do While Cells(i, 1).Value <> ""

‘formula

If Cells(i, 2) = 0 Or Cells(i, 3) = 0 Or Cells(i, 4) = 0 Or Cells(i, 5) = 0 Or Cells(i, 6) < 0 Then Cells(i, 8).Value = "" Else Cells(i, 8).Value = Cells(i + 1, 1).Value - Cells(i, 1).Value
On Error Resume Next

If Cells(i, 8) < 0 Then Cells(i, 8).Value = ""

On Error Resume Next

     i = i + 1



Loop

End Sub