Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default if & and code problem

I have spent hours trying to correct this Excel code and am considering
resigning.
Can anyone help ?

ActiveCell.Formula =
"=IF((C2)="""",""1"",IF(AND((A2)=""enddate"",(E2)< ""01/01/01"",(E2)<NOW()+14),""2"",if(and((A2)=""startem"", date(0,month(e2),day(e2))date(0,month(now()),day( now())),(e2)=""3""),""XXX""))"


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default if & and code problem

I answered this in the other thread when you asked it yesterday.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jocker" wrote in message
. nl...
I have spent hours trying to correct this Excel code and am considering
resigning.
Can anyone help ?

ActiveCell.Formula =

"=IF((C2)="""",""1"",IF(AND((A2)=""enddate"",(E2)< ""01/01/01"",(E2)<NOW()+1
4),""2"",if(and((A2)=""startem"",date(0,month(e2), day(e2))date(0,month(now(
)),day(now())),(e2)=""3""),""XXX""))"




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default if & and code problem

Sorry, Bob. I did see your reply as to how to do it, but not on why my
expanded code fails.Take pity on a pensioner trying to help his daughter.


"Bob Phillips" wrote in message
...
I answered this in the other thread when you asked it yesterday.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jocker" wrote in message
. nl...
I have spent hours trying to correct this Excel code and am considering
resigning.
Can anyone help ?

ActiveCell.Formula =

"=IF((C2)="""",""1"",IF(AND((A2)=""enddate"",(E2)< ""01/01/01"",(E2)<NOW()+1
4),""2"",if(and((A2)=""startem"",date(0,month(e2), day(e2))date(0,month(now(
)),day(now())),(e2)=""3""),""XXX""))"






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default if & and code problem

It fails because it is syntactically incorrect. You have brackets in the
wrong place.

This works, or at least doesn't throw an error

Dim sFormula As String

sFormula = _
"=IF(C2="""",""1"",IF(AND(A2=""enddate"",E2<" "01/01/01"",E2<NOW()+14),""2""
,if(and(A2=""startem"",Date(0,Month(E2),Day(E2))D ate(0,Month(Now()),Day(Now
()))),E2=""3"",""XXX"")))"
ActiveCell.Formula = sFormula

The way I checked it was to take the string you were trying to use, display
that in the immediate window using the print method (? in the immediate
window), and then take the displayed value and stick it in a cell. Much
easier to see the problem then.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jocker" wrote in message
. nl...
Sorry, Bob. I did see your reply as to how to do it, but not on why my
expanded code fails.Take pity on a pensioner trying to help his daughter.


"Bob Phillips" wrote in message
...
I answered this in the other thread when you asked it yesterday.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jocker" wrote in message
. nl...
I have spent hours trying to correct this Excel code and am considering
resigning.
Can anyone help ?

ActiveCell.Formula =


"=IF((C2)="""",""1"",IF(AND((A2)=""enddate"",(E2)< ""01/01/01"",(E2)<NOW()+1

4),""2"",if(and((A2)=""startem"",date(0,month(e2), day(e2))date(0,month(now(
)),day(now())),(e2)=""3""),""XXX""))"








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default if & and code problem

Many thanks, Bob. Can u explain in more detail how you found the fault.

Not sure about "print method"

jeff
+++++++++++++++++++++++++++++++++++++
"Bob Phillips" wrote in message
...
It fails because it is syntactically incorrect. You have brackets in the
wrong place.

This works, or at least doesn't throw an error

Dim sFormula As String

sFormula = _
"=IF(C2="""",""1"",IF(AND(A2=""enddate"",E2<" "01/01/01"",E2<NOW()+14),""2""
,if(and(A2=""startem"",Date(0,Month(E2),Day(E2))D ate(0,Month(Now()),Day(Now
()))),E2=""3"",""XXX"")))"
ActiveCell.Formula = sFormula

The way I checked it was to take the string you were trying to use,
display
that in the immediate window using the print method (? in the immediate
window), and then take the displayed value and stick it in a cell. Much
easier to see the problem then.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jocker" wrote in message
. nl...
Sorry, Bob. I did see your reply as to how to do it, but not on why my
expanded code fails.Take pity on a pensioner trying to help his daughter.


"Bob Phillips" wrote in message
...
I answered this in the other thread when you asked it yesterday.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jocker" wrote in message
. nl...
I have spent hours trying to correct this Excel code and am
considering
resigning.
Can anyone help ?

ActiveCell.Formula =


"=IF((C2)="""",""1"",IF(AND((A2)=""enddate"",(E2)< ""01/01/01"",(E2)<NOW()+1

4),""2"",if(and((A2)=""startem"",date(0,month(e2), day(e2))date(0,month(now(
)),day(now())),(e2)=""3""),""XXX""))"












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default if & and code problem

Okay, I'll try.

Your original formula was

ActiveCell.Formula =
"=IF((C2)="""",""1"",IF(AND((A2)=""enddate"",(E2)< ""01/01/01"",(E2)<NOW()+1
4),""2"",if(and((A2)=""startem"",date(0,month(e2), day(e2))date(0,month(now(
)),day(now())),(e2)=""3""),""XXX""))"

I took this part and in the immediate window in the VBIDE (Ctrl-G) I did

?"=IF((C2)="""",""1"",IF(AND((A2)=""enddate"",(E2) <""01/01/01"",(E2)<NOW()+
14),""2"",if(and((A2)=""startem"",date(0,month(e2) ,day(e2))date(0,month(now
()),day(now())),(e2)=""3""),""XXX""))"

the ? is print. This gave a result of

=IF((C2)="","1",IF(AND((A2)="enddate",(E2)<"01/01/01",(E2)<NOW()+14),"2",if
(and((A2)="startem",date(0,month(e2),day(e2))date (0,month(now()),day(now())
),(e2)="3"),"XXX"))


which I could copy, paste ina worksheet ecll, and see the problem more
easily.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jocker" wrote in message
. nl...
Many thanks, Bob. Can u explain in more detail how you found the fault.

Not sure about "print method"

jeff
+++++++++++++++++++++++++++++++++++++
"Bob Phillips" wrote in message
...
It fails because it is syntactically incorrect. You have brackets in the
wrong place.

This works, or at least doesn't throw an error

Dim sFormula As String

sFormula = _

"=IF(C2="""",""1"",IF(AND(A2=""enddate"",E2<" "01/01/01"",E2<NOW()+14),""2""

,if(and(A2=""startem"",Date(0,Month(E2),Day(E2))D ate(0,Month(Now()),Day(Now
()))),E2=""3"",""XXX"")))"
ActiveCell.Formula = sFormula

The way I checked it was to take the string you were trying to use,
display
that in the immediate window using the print method (? in the immediate
window), and then take the displayed value and stick it in a cell. Much
easier to see the problem then.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jocker" wrote in message
. nl...
Sorry, Bob. I did see your reply as to how to do it, but not on why my
expanded code fails.Take pity on a pensioner trying to help his

daughter.


"Bob Phillips" wrote in message
...
I answered this in the other thread when you asked it yesterday.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jocker" wrote in message
. nl...
I have spent hours trying to correct this Excel code and am
considering
resigning.
Can anyone help ?

ActiveCell.Formula =



"=IF((C2)="""",""1"",IF(AND((A2)=""enddate"",(E2)< ""01/01/01"",(E2)<NOW()+1


4),""2"",if(and((A2)=""startem"",date(0,month(e2), day(e2))date(0,month(now(
)),day(now())),(e2)=""3""),""XXX""))"












Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If/then code problem peter.thompson[_12_] Excel Programming 2 December 27th 05 03:19 AM
Can anyone see the problem with this code? Cody Excel Programming 5 July 21st 05 11:23 PM
code problem scrabtree23[_2_] Excel Programming 2 September 16th 04 05:28 AM
Problem with this code Jonsson[_8_] Excel Programming 2 April 21st 04 01:07 PM
Code problem Rick[_11_] Excel Programming 1 August 8th 03 04:25 AM


All times are GMT +1. The time now is 12:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"