adding to cells

  • Thread starter Thread starter dstiefe
  • Start date Start date
D

dstiefe

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
 
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??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top