working with IF statements

M

matty_g

Hello,

I have a function which checks for data in a certain field if data is
in the field I want my function to do nothing and the value currently
in the field to stay there, however; if there is not data in the field
I would like a random number to be chose. The problem I am having is
when the function is false I don't know how to just keep the same value
when I do it like this:

=IF(A3="",(RANDBETWEEN(1,E2)))

it fills the field with FALSE, if the value is false there will be data
in this field already and I want that data to remain there. Any idea?

Thanks for your help!!
 
B

Bill Kuunders

=IF(A3="",RANDBETWEEN(1,E2),A3)
should work
note, no bracket in front of RANDBETWEEN
 
D

dominicb

Good evening matty_g

I think your problem here is nothing more sinister than a slight syntax
hiccup. The =IF() function must always have the condition plus two
arguments (what to do if TRUE, and what to do if FALSE) - you were
missing the FALSE argument so Excel just filled in the best it could
rather than give you an error. Your slightly rewritten formula should
help out.

=IF(A3="",RANDBETWEEN(1,E2),A3)

HTH

DominicB
 
M

matty_g

Thanks for your help,

however I am still having the problem with this fact, when the value i
false there is already a value in the field. I would like to just kee
this value and do nothing to it. That is my problem.

something like this =IF(A2="",RANDBETWEEN(1,E2),'-do nothing-')

do nothing mean just leave it the way it is. I was also trying t
figure out how to possibly save the value to a variable then displa
the variable if false. Not sure if this is possible. I have som
programming experience but not much excel. It was just a thought du
to the programming I have done. anyways any help would be greatl
appreciated

Thanks agai
 
M

matty_g

Hi, thanks

the problem is that when false, there is already a value in that fiel
which I would just like to keep there, not get one from anywhere else.
Like this:

=IF(A3="", RANDBETWEEN(1,E2), '-do nothing-')

meaning just leave the current value there. I don't know how t
accomplish this. I was looking at the possiblity of some how saving th
value into some sort of variable. I have some programming experienc
but not a whole lot with excel so this was just a thought.

Any help would be greatly appreciated
 
B

Bill Kuunders

Matty

I read your conditions as...........
if a3 is empty take a random number between 1 and e2
If a3 is not empty, return a3.

The functions in our replies
=IF(A3="",RANDBETWEEN(1,E2),A3) should do that.

"the problem is that when false....." which cell is false?

Where are you entering the function? In cell e3?
 
M

matty_g

the data should go into f2...but when I put f2 for the value if false i
gives me an error. But if it is false I just want the value in f2 t
remain the sam
 
M

MrShorty

One thing I see missing from the above posts is that, because you ar
setting up a circular reference, you need to turn iteration on via th
Options dialog. Then enter the formula f2=IF(a3="",RAND....,f2)

HT
 
Top