# How to turn Functions into Code

#### autigers

##### Board Regular
I have the following Formula that I wish to put in code and then transfer the sums to a seperate sheet in the same workbook. After the data tranfer is complete, I would like to clear the input sheet ....
=IF(C2="","",IF
(E2="","",IF(E2
<D2,IF(F2="",
E2+1-D2,(E2+
1)-(D2+\$V\$2)
),IF(F2="",E2-
D2,D2-(E2+
\$V\$2)))))

Any help would be greatly appreciated.

#### acw

##### MrExcel MVP
Hi

Can you please review the formula. As it stands, I get an error when entering. Somewhere at the end of line2 and start of line3 - I think.

Tony

#### autigers

##### Board Regular
The end of the second line should read "IF(E2<D2," Not sure but the board doesn't like my "<" symbol ...

#### autigers

##### Board Regular
Sorry .. it sholud be IF(E2 Is Less than D2,IF(F2="",... The board cuts off my message if I use a less than symbol ....

Did that work ?

#### Scott Huish

##### MrExcel MVP
Paste in you formula, highlight it and click on the code button, we will be able to see it then and do not break it into multiple lines.

#### poorwallace

##### Active Member
stictly going by trying to make the formula correct, this was what I came up with...

Code:
``=IF(C2="","",IF(E2="","",IF(E2+1-D2,((E2+1)-(D2+\$V\$2)),IF(F2="",E2-D2,D2-(E2+\$V\$2)))))``

#### autigers

##### Board Regular
Code:
``=IF(C2="","",IF(E2="","",IF(E2<D2,IF(F2="",E2+1-D2,(E2+1)-(D2+\$V\$2)),IF(F2="",E2-D2,D2-(E2+\$V\$2)))))``

#### acw

##### MrExcel MVP
Hi

Got the formula. Now go back to the original question. Do you want to put this formula into a cell and copy it to a range, then take the results to another place, or do you want this evaluated in code, with the results put onto the sheet somewhere???

Tony

#### autigers

##### Board Regular
The latter ...
It now resides in every row in column G. From Rows G2:G150.
I would like to have the code loop through the range in the formula and perform the math placing the results in
Same Worksheet "DailyInput" Column G.

I will try to provide a screen shot of the sheet .... Visual is sometimes better.

Thanks