+ Reply to Thread
Results 1 to 11 of 11

if & and code problem

  1. #1
    jocker
    Guest

    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. #2
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #3
    jocker
    Guest

    Re: 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" <[email protected]> wrote in message
    news:%[email protected]...
    >I answered this in the other thread when you asked it yesterday.
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from email address if mailing direct)
    >
    > "jocker" <[email protected]> wrote in message
    > news:[email protected]...
    >> 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. #4
    Bob Phillips
    Guest

    Re: 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))>Date(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" <[email protected]> wrote in message
    news:[email protected]...
    > 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" <[email protected]> wrote in message
    > news:%[email protected]...
    > >I answered this in the other thread when you asked it yesterday.
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (remove nothere from email address if mailing direct)
    > >
    > > "jocker" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> 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. #5
    jocker
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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))>Date(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" <[email protected]> wrote in message
    > news:[email protected]...
    >> 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" <[email protected]> wrote in message
    >> news:%[email protected]...
    >> >I answered this in the other thread when you asked it yesterday.
    >> >
    >> > --
    >> > HTH
    >> >
    >> > Bob Phillips
    >> >
    >> > (remove nothere from email address if mailing direct)
    >> >
    >> > "jocker" <[email protected]> wrote in message
    >> > news:[email protected]...
    >> >> 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. #6
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > Many thanks, Bob. Can u explain in more detail how you found the fault.
    >
    > Not sure about "print method"
    >
    > jeff
    > +++++++++++++++++++++++++++++++++++++
    > "Bob Phillips" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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))>Date(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" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> 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" <[email protected]> wrote in message
    > >> news:%[email protected]...
    > >> >I answered this in the other thread when you asked it yesterday.
    > >> >
    > >> > --
    > >> > HTH
    > >> >
    > >> > Bob Phillips
    > >> >
    > >> > (remove nothere from email address if mailing direct)
    > >> >
    > >> > "jocker" <[email protected]> wrote in message
    > >> > news:[email protected]...
    > >> >> 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""))"
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >




  7. #7
    jocker
    Guest

    Re: if & and code problem

    That's what I did but on hitting the Enter key all I get is "compile error"
    and nothing in the Intermediate window changes

    ++++++++++++++++


    "Bob Phillips" <[email protected]> wrote in message
    news:%[email protected]...
    > 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" <[email protected]> wrote in message
    > news:[email protected]...
    >> Many thanks, Bob. Can u explain in more detail how you found the fault.
    >>
    >> Not sure about "print method"
    >>
    >> jeff
    >> +++++++++++++++++++++++++++++++++++++
    >> "Bob Phillips" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > 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))>Date(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" <[email protected]> wrote in message
    >> > news:[email protected]...
    >> >> 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" <[email protected]> wrote in message
    >> >> news:%[email protected]...
    >> >> >I answered this in the other thread when you asked it yesterday.
    >> >> >
    >> >> > --
    >> >> > HTH
    >> >> >
    >> >> > Bob Phillips
    >> >> >
    >> >> > (remove nothere from email address if mailing direct)
    >> >> >
    >> >> > "jocker" <[email protected]> wrote in message
    >> >> > news:[email protected]...
    >> >> >> 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""))"
    >> >> >>
    >> >> >>
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >




  8. #8
    Bob Phillips
    Guest

    Re: if & and code problem

    You shouldn't get a compile error as you are just printing a string. You did
    only copy the parts between the first and last quotes, not the Activecell
    bit as well?

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "jocker" <[email protected]> wrote in message
    news:[email protected]...
    > That's what I did but on hitting the Enter key all I get is "compile

    error"
    > and nothing in the Intermediate window changes
    >
    > ++++++++++++++++
    >
    >
    > "Bob Phillips" <[email protected]> wrote in message
    > news:%[email protected]...
    > > 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" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> Many thanks, Bob. Can u explain in more detail how you found the fault.
    > >>
    > >> Not sure about "print method"
    > >>
    > >> jeff
    > >> +++++++++++++++++++++++++++++++++++++
    > >> "Bob Phillips" <[email protected]> wrote in message
    > >> news:[email protected]...
    > >> > 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))>Date(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" <[email protected]> wrote in message
    > >> > news:[email protected]...
    > >> >> 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" <[email protected]> wrote in message
    > >> >> news:%[email protected]...
    > >> >> >I answered this in the other thread when you asked it yesterday.
    > >> >> >
    > >> >> > --
    > >> >> > HTH
    > >> >> >
    > >> >> > Bob Phillips
    > >> >> >
    > >> >> > (remove nothere from email address if mailing direct)
    > >> >> >
    > >> >> > "jocker" <[email protected]> wrote in message
    > >> >> > news:[email protected]...
    > >> >> >> 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""))"
    > >> >> >>
    > >> >> >>
    > >> >> >
    > >> >> >
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >




  9. #9
    Ron Dean
    Guest

    Re: if & and code problem

    Yes, I entered it without the "Activecell" phrase. Even when I copy & paste
    the code you put in the Immediate window, I get "Compile Error. Expected:
    Line number or label or statement or end of statement

    Sorry to bother you again
    +++++++++++++


    "Bob Phillips" <[email protected]> wrote in message
    news:[email protected]...
    > You shouldn't get a compile error as you are just printing a string. You
    > did
    > only copy the parts between the first and last quotes, not the Activecell
    > bit as well?
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from email address if mailing direct)
    >
    > "jocker" <[email protected]> wrote in message
    > news:[email protected]...
    >> That's what I did but on hitting the Enter key all I get is "compile

    > error"
    >> and nothing in the Intermediate window changes
    >>
    >> ++++++++++++++++
    >>
    >>
    >> "Bob Phillips" <[email protected]> wrote in message
    >> news:%[email protected]...
    >> > 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" <[email protected]> wrote in message
    >> > news:[email protected]...
    >> >> Many thanks, Bob. Can u explain in more detail how you found the
    >> >> fault.
    >> >>
    >> >> Not sure about "print method"
    >> >>
    >> >> jeff
    >> >> +++++++++++++++++++++++++++++++++++++
    >> >> "Bob Phillips" <[email protected]> wrote in message
    >> >> news:[email protected]...
    >> >> > 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))>Date(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" <[email protected]> wrote in message
    >> >> > news:[email protected]...
    >> >> >> 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" <[email protected]> wrote in message
    >> >> >> news:%[email protected]...
    >> >> >> >I answered this in the other thread when you asked it yesterday.
    >> >> >> >
    >> >> >> > --
    >> >> >> > HTH
    >> >> >> >
    >> >> >> > Bob Phillips
    >> >> >> >
    >> >> >> > (remove nothere from email address if mailing direct)
    >> >> >> >
    >> >> >> > "jocker" <[email protected]> wrote in message
    >> >> >> > news:[email protected]...
    >> >> >> >> 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""))"
    >> >> >> >>
    >> >> >> >>
    >> >> >> >
    >> >> >> >
    >> >> >>
    >> >> >>
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >




  10. #10
    Bob Phillips
    Guest

    Re: if & and code problem

    Ron,

    I think the problem is arising from copying from the NG getting linefeeds
    embedded. This

    ?"=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""))"

    has a CR after the + and the now on the second line. Ensure that you remove
    them so that the string is contiguous, it should work okay then.

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Ron Dean" <[email protected]> wrote in message
    news:[email protected]...
    > Yes, I entered it without the "Activecell" phrase. Even when I copy &

    paste
    > the code you put in the Immediate window, I get "Compile Error. Expected:
    > Line number or label or statement or end of statement
    >
    > Sorry to bother you again
    > +++++++++++++
    >
    >
    > "Bob Phillips" <[email protected]> wrote in message
    > news:[email protected]...
    > > You shouldn't get a compile error as you are just printing a string. You
    > > did
    > > only copy the parts between the first and last quotes, not the

    Activecell
    > > bit as well?
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (remove nothere from email address if mailing direct)
    > >
    > > "jocker" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> That's what I did but on hitting the Enter key all I get is "compile

    > > error"
    > >> and nothing in the Intermediate window changes
    > >>
    > >> ++++++++++++++++
    > >>
    > >>
    > >> "Bob Phillips" <[email protected]> wrote in message
    > >> news:%[email protected]...
    > >> > 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" <[email protected]> wrote in message
    > >> > news:[email protected]...
    > >> >> Many thanks, Bob. Can u explain in more detail how you found the
    > >> >> fault.
    > >> >>
    > >> >> Not sure about "print method"
    > >> >>
    > >> >> jeff
    > >> >> +++++++++++++++++++++++++++++++++++++
    > >> >> "Bob Phillips" <[email protected]> wrote in message
    > >> >> news:[email protected]...
    > >> >> > 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))>Date(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" <[email protected]> wrote in message
    > >> >> > news:[email protected]...
    > >> >> >> 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" <[email protected]> wrote in

    message
    > >> >> >> news:%[email protected]...
    > >> >> >> >I answered this in the other thread when you asked it yesterday.
    > >> >> >> >
    > >> >> >> > --
    > >> >> >> > HTH
    > >> >> >> >
    > >> >> >> > Bob Phillips
    > >> >> >> >
    > >> >> >> > (remove nothere from email address if mailing direct)
    > >> >> >> >
    > >> >> >> > "jocker" <[email protected]> wrote in message
    > >> >> >> > news:[email protected]...
    > >> >> >> >> 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""))"
    > >> >> >> >>
    > >> >> >> >>
    > >> >> >> >
    > >> >> >> >
    > >> >> >>
    > >> >> >>
    > >> >> >
    > >> >> >
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >




  11. #11
    Ron Dean
    Guest

    Re: if & and code problem

    It works a treat, many thanks
    jeff
    ++++++++++++++++++++++
    "Bob Phillips" <[email protected]> wrote in message
    news:elx%[email protected]...
    > Ron,
    >
    > I think the problem is arising from copying from the NG getting linefeeds
    > embedded. This
    >
    > ?"=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""))"
    >
    > has a CR after the + and the now on the second line. Ensure that you
    > remove
    > them so that the string is contiguous, it should work okay then.
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from email address if mailing direct)
    >
    > "Ron Dean" <[email protected]> wrote in message
    > news:[email protected]...
    >> Yes, I entered it without the "Activecell" phrase. Even when I copy &

    > paste
    >> the code you put in the Immediate window, I get "Compile Error. Expected:
    >> Line number or label or statement or end of statement
    >>
    >> Sorry to bother you again
    >> +++++++++++++
    >>
    >>
    >> "Bob Phillips" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > You shouldn't get a compile error as you are just printing a string.
    >> > You
    >> > did
    >> > only copy the parts between the first and last quotes, not the

    > Activecell
    >> > bit as well?
    >> >
    >> > --
    >> > HTH
    >> >
    >> > Bob Phillips
    >> >
    >> > (remove nothere from email address if mailing direct)
    >> >
    >> > "jocker" <[email protected]> wrote in message
    >> > news:[email protected]...
    >> >> That's what I did but on hitting the Enter key all I get is "compile
    >> > error"
    >> >> and nothing in the Intermediate window changes
    >> >>
    >> >> ++++++++++++++++
    >> >>
    >> >>
    >> >> "Bob Phillips" <[email protected]> wrote in message
    >> >> news:%[email protected]...
    >> >> > 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" <[email protected]> wrote in message
    >> >> > news:[email protected]...
    >> >> >> Many thanks, Bob. Can u explain in more detail how you found the
    >> >> >> fault.
    >> >> >>
    >> >> >> Not sure about "print method"
    >> >> >>
    >> >> >> jeff
    >> >> >> +++++++++++++++++++++++++++++++++++++
    >> >> >> "Bob Phillips" <[email protected]> wrote in message
    >> >> >> news:[email protected]...
    >> >> >> > 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))>Date(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" <[email protected]> wrote in message
    >> >> >> > news:[email protected]...
    >> >> >> >> 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" <[email protected]> wrote in

    > message
    >> >> >> >> news:%[email protected]...
    >> >> >> >> >I answered this in the other thread when you asked it
    >> >> >> >> >yesterday.
    >> >> >> >> >
    >> >> >> >> > --
    >> >> >> >> > HTH
    >> >> >> >> >
    >> >> >> >> > Bob Phillips
    >> >> >> >> >
    >> >> >> >> > (remove nothere from email address if mailing direct)
    >> >> >> >> >
    >> >> >> >> > "jocker" <[email protected]> wrote in message
    >> >> >> >> > news:[email protected]...
    >> >> >> >> >> 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1