If statement

S

Secret Squirrel

I'm trying to write an IF statement using a text value but it's not returning
what I need. Is there something special I need to do with the format of the
field I'm using in my statement?

Formula: =IF(E2="Closed","",U2)

All I'm saying is that if the value in E2 equals "Closed" then put nothing
but if it's not true then copy the value from U2. The value in U2 is a dollar
amount. It's returning the false value for this when the actual value in E2
is Closed. Am I missing something?
 
G

Gary''s Student

Check that E2 is EXACTLY what's in the formula and that there is no extra
blank after it like "Closed "
 
D

Dave Peterson

I'd guess that there's more stuff in E2 than just Closed. Any leading/trailing
white space?

if you type:
=len(e2)
do you get 6?

And don't forget to check for a simple spelling error.
 
S

Secret Squirrel

Yep it's exactly the way it needs to be. No extra spaces or anything like
that. The format for E2 is set to Text. What else can I check?
 
S

Secret Squirrel

No I get 20. Why is that? The spelling is correct and there are no leading or
trailing spaces.
 
G

Gary''s Student

Check the formula bar as well as the cell. There is extra stuff hidden in
there somewhere.
 
S

Secret Squirrel

Found it. When I clicked in the formula bar there were extra spaces trailing
the word. How do I get rid of those for all my rows? I have over 1000 rows.
I'm importing this data from my MRP system so maybe it's bringing them in
during the import?
 
D

David Biddulph

Try the TRIM() function.
--
David Biddulph

Secret Squirrel said:
Found it. When I clicked in the formula bar there were extra spaces
trailing
the word. How do I get rid of those for all my rows? I have over 1000
rows.
I'm importing this data from my MRP system so maybe it's bringing them in
during the import?
 
G

Gary''s Student

If they are truly spaces (and not some other non-printing character), then
you can use

Edit > Find and then Replace to remove either all of them or some of them.
 
D

Dave Peterson

if the data is in one column, you can select that column and do
data|text to columns and then click finish.

(or do this for each column to be fixed).

Or you could modify your formula:

=IF(E2="Closed","",U2)
becomes
=IF(trim(E2)="Closed","",U2)
or
=IF(trim(E2)="Closed","",trim(U2))

Personally, I'd try to clean up the data and not try to modify the
formulas--it's just too easy to add a formula and forget that the data needs to
be cleaned up (again and again and again...)
 
S

Secret Squirrel

They are in fact spaces. I did remove them for some of the cells but how do I
know how many spaces there are on the other cells? For example if the text
"Closed" is in that cell then there are 14 spaces after it. It the word
"Open" is in there then there are 16 spaces. Is there any way just to remove
them all without figuring out how many there are after every word?
 
D

driller

Hi David Bid, in english you are correct, the If function easily trace the
data content himself when the formula writer is cautious enough before
reproducing basic IF formulas produce for thousands of line.....Nice problem
squirrel....hope u can give more....
 
D

Dave Peterson

If there are no other spaces in the cell (like: "in work "), you could do
this:

Select the range
edit|replace
what: (spacebar)
with: (leave blank)
Make sure that the "match entire cell contents" box under the Options button is
not checked.
Then click
replace all

If you do have "In Work " in a cell, it will become "InWork". So be careful.
 
S

Secret Squirrel

Thanks! I'm trying to come up with more problems for you guys! I just wish I
could learn as much as you.
 
G

Gary''s Student

If you feel comfortable with VBA, this small macro will find all the spaces
in the worksheet and remove them:

Sub SpaceAttacker()
Dim r As Range, rr As Range
Set rr = ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)
For Each r In rr
r.Value = Application.Substitute(r.Value, " ", "")
Next
End Sub

It changes only constants, not formulas
 
S

Secret Squirrel

Yes I am comfortable with VBA. I will give this a shot. Thanks for all your
help!

SS
 

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

Top