ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   adding to cells (https://www.excelbanter.com/excel-programming/408296-adding-cells.html)

dstiefe

adding to cells
 
I have a financial model that i've put together that is a 5 year projection
by month

i need to add a "if x <0,0,1" type of function within the cells. is there
anyway through VBA that i can scroll through the cells rather than manually.

i am somewhat familiar with VBA...

i would think that i have to create a variable that captures the existing
formula...then put the function in front of the existing formula...and then
update the variable..

but i'm not sure how to do it.

thank you

Gary''s Student

adding to cells
 
Without an example, this is only a guess:

Sub formulariser()
For Each r In Selection
If r.HasFormula Then
v = r.Formula
v = Right(v, Len(v) - 1)
r.Formula = "=if(" & v & "<0,0,1)"
End If
Next
End Sub

So if a cell has a formula like:

=A1+B1
then the sub would change it into:

=IF(A1+B1<0,0,1)

Is this what you want??
--
Gary''s Student - gsnu200775


"dstiefe" wrote:

I have a financial model that i've put together that is a 5 year projection
by month

i need to add a "if x <0,0,1" type of function within the cells. is there
anyway through VBA that i can scroll through the cells rather than manually.

i am somewhat familiar with VBA...

i would think that i have to create a variable that captures the existing
formula...then put the function in front of the existing formula...and then
update the variable..

but i'm not sure how to do it.

thank you



All times are GMT +1. The time now is 01:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com