Results 1 to 7 of 7

Thread: [RESOLVED] IF Clause - syntx error

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    167

    Resolved [RESOLVED] IF Clause - syntx error

    what is the syntax error below
    If Ucase(aSheet.Cells(4."e")).value = "ABCD" AND if aSheet.Cells(i,"d") <> "" And dic.Exists((aSheet.Cells(i,"d")) then
    MsgBox ("ABCD ORG NOT CONSISTENT" )
    Exit Sub

    End if

  2. #2
    Addicted Member
    Join Date
    Jan 2008
    Location
    Pittsburgh
    Posts
    169

    Re: IF Clause - syntx error

    a couple of things I see. There is a . instead of a , between the 4 and "e" in the first cell reference.
    Also you should reference the columns by number and not character so you'd use
    Code:
    If Ucase(aSheet.Cells(4, 5)).value = "ABCD" AND if aSheet.Cells(i,4) <> "" And dic.Exists((aSheet.Cells(i,4)) then
    MsgBox ("ABCD ORG NOT CONSISTENT" )
    Exit Sub
    If you're going to be crazy, you have to get paid for it or else you're going to be locked up. -- Hunter Thompson

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    167

    Re: IF Clause - syntx error

    Still it shows syntax error

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: IF Clause - syntx error

    If Ucase(aSheet.Cells(4."e")).value = "ABCD" AND aSheet.Cells(i,"d") <> "" And dic.Exists((aSheet.Cells(i,"d")) then
    don't need 2 ifs
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    167

    Re: IF Clause - syntx error

    westconn
    actaully i want
    for example if the d cell has
    par
    par
    car
    i need only take par and par only if it is anythign other than par
    it comes mSG BOX NOT CONSTRAINT
    what i did the above is that one is right? please let me know
    thanks

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: IF Clause - syntx error

    i don't believe you need to check if cells(i,"d") is both <> "" and dic.exists, if it was "" then it can not dic.exists, whatever dic.exists is

    if you are not sure why it is returning false you need to evaluate both parts separately to fond out what the problem is
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Lively Member
    Join Date
    May 2007
    Posts
    70

    Re: IF Clause - syntx error

    Quote Originally Posted by india123
    what is the syntax error below
    If Ucase(aSheet.Cells(4."e")).value = "ABCD" AND if aSheet.Cells(i,"d") <> "" And dic.Exists((aSheet.Cells(i,"d")) then
    MsgBox ("ABCD ORG NOT CONSISTENT" )
    Exit Sub

    End if

    Hi there...

    I believe apart from the .cells(R,C).value number issue the problem with the syntax is that you did not nest the second if statement.

    If Ucase(aSheet.Cells(4."e")).value = "ABCD" then
    if aSheet.Cells(i,"d") <> "" And dic.Exists((aSheet.Cells(i,"d")) then
    MsgBox ("ABCD ORG NOT CONSISTENT" )
    Exit Sub
    end if
    End if
    cheers

Posting Permissions

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



Click Here to Expand Forum to Full Width