• Status: Solved
• Priority: Medium
• Security: Public
• Views: 286

# I need to update the following formula

I need to update the following formula:

=IF(AND(g10>J10,K10>g10),"test1",IF(g10>K10,"test2",""))

I neeed to update it to include: (LEFT(G10, LEN(G10)-4). I cant get the sytnax right and it keeps erroring out.

G10 has a space and (X) in the cell that I need to be able to remove and look just at the date.
0
wrt1mea
• 7
• 5
• 3
• +2
1 Solution

will you post your sample WB?
0

Commented:
pls share some example data/sheet
0

Network ManagerCommented:
Not sure what you are looking for without the sample but it sounds like you maybe only want to read the first 4 characters of G10 or you want everthing after the first 4 characters?

left(g10,4) will get the first 4

RIGHT(g10, LEN(g10)-4) will get everything after the first 4
0

Author Commented:
Here is a sample
Ex-Ech-3-11-14.xlsx
0

Finance AnalystCommented:
@pony10us
=(LEFT(G10, LEN(G10)-4)

Will give everything but the last 4 characters.

Thanks
Rob H
0

Author Commented:
Thats all I want, everything except the last 4 in G10....

Now if someone could put that in the formula, that would be great. I kept getting errors.
0

Finance AnalystCommented:
Try this:

=IF(AND(LEFT(G10,LEN(G10)-4)*1>J10,K10>LEFT(G10,LEN(G10)-4)*1),"test1",IF(LEFT(G10,LEN(G10)-4)*1>K10,"test2",""))

I have included *1 to force excel to recognise it as a number; maybe thats why it was still giving errors.

Thanks
Rob H
0

Finance AnalystCommented:
To get syntax right I typed the formula in a separate cell:

=LEFT(G10,LEN(G10)-4)*1

Then copied the text of the formula to the clipboard, press F2 and highlight the formula in the formula bar and Ctrl C.

Then selected T10 and U10 and did edit replace:

Find         G10
Replace   LEFT(G10,LEN(G10)-4)*1  (pasted in)

Click Replace All.

Thanks
Rob H
0

Network ManagerCommented:
Rob,

Wouldn't this work as well?

=IF(AND(LEFT(G10,LEN(G10)-4)>J10,(K10>G10)),"test1",IF(LEFT(G10,LEN(G10)-4)>K10,"test2",""))

At least it seems to work in my tests.

EDIT:

Actually,  I just tested it agains some lines that I think should have resulted in "test1" (line 14 for example) and it didn't so I guess my formula isn't quite correct.
0

Author Commented:
GREAT JOB!

THANKS TO EVERYONE FOR THE HELP!
0

Finance AnalystCommented:
Pony - what locale are you using?

The sample data that came through was in mm/dd/yyyy format so I had to tweak it a little bit first.

The sample on row 10 had 6/30/2014 (E) so I manually changed to 30/6/2014 (E) to allow for UK date recognition.

Thanks
Rob
0

Network ManagerCommented:
Rob,

I am in US so no need to alter the format from the original.

I wanted to play around some more to try and see where it was failing.

Givens:

G10 = 6/30/14 (E)
H10 = 9/24/14
J10 = 4/12/14
K10 = 11/12/14

In Cell L10 I put:    =(LEFT(G10,LEN(G10)-4))   which returned     6/30/14

In Cell M10 I put:    =IF(L10>J10,"yes","no")     which returned       yes
(6/30/14>4/12/14)

In Cell N10 I put:    =IF(K10>L10,"yes","no")     which returned       no
(this returned incorrectly)

I changed Cell N10 to:    =IF(K10>L10,K10,L10)     which returned  6/30/14
(also incorrect)

The format of both K10 and L10 is date 3/14/14 so not sure why everything worked until the final test.
0

Finance AnalystCommented:
Although the LEFT function returned what looks like a date, is it actually a date. Format it as comma or another number format and it should be 41820; if not then its not a true date.

Alternatively shrink the column so the value won't fit. A number will go to ### whereas text will either partly disappear or run onto the next cell.

I have replicated the little test above and the text value "6/30/14" returns Yes and No as per your results but replacing the 6/30/14 with (for my locale) 30/06/14 returns the correct answers.

Alternative to the *1 would be DATEVALUE(LEFT(G10,LEN(G10)-4)) which should give a date in your locale as it will recognise the format of 6/30/14 as being 30 June, that didn't work for UK locale.

Thanks
Rob
0

Network ManagerCommented:
Rob,

Thank you,  after playing around I found that the formula in L10

=(LEFT(G10,LEN(G10)-4))

does NOT return a date.  Not sure what it returns but not the date 6/3/14 even though the cell is formated for that date format.  I formated the cell as General and it still looked the same.

I changed it to:

=(LEFT(G10,LEN(G10)-4))*1

and it returned the date value (when changing the cell format to general it gave the number 41820

All other calculations work properly with the *1 in the proper places.
0

Finance AnalystCommented:
The LEFT part of the formula purely pulls a string of text. Putting the *1 on thend tells Excel to try and do some maths with it. If it were ordinary text it would fail but its clever enough to recognise it as a date so does the necessary calcs and returns the date.

Thanks
Rob
0

Network ManagerCommented:
Thank you again Rob.  That's why I like EE.  Always something new to learn while helping others at the same time.  :)
0

Finance AnalystCommented:
Every day is a school day!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.