Results 1 to 11 of 11
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    IF STATEMENT (Excel 2000)

    Hi all,

    I'm trying to test the condition of a cell by using color, I have been trying to minimize code my using this statement, I thought it worked, but it doesn't, doesw any one know why it doesn't work? when debugging this, I see that it doesn't test the if statement.


    Thanks,
    Darryl.

    If Worksheets(1).Range("F11").Interior.ColorIndex = 6 Or 4 Or 5 Or 3 Or 39 Or 7 Then
    With FrmPressTimeBook.Listtimebooked
    .AddItem "8:00"
    End With
    End If

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: IF STATEMENT (Excel 2000)

    You can't express multiple conditions in an if statement like that. You'd probably be better off using a Select Case construct:
    <code>
    Ind = Worksheets(1).Range("F11").Interior.ColorIndex

    Select Case Ind

    Case 6, 4, 5, 3, 39, 7
    With FrmPressTimeBook.Listtimebooked
    .AddItem "8:00"
    End With

    Case Else

    End Select
    </code>
    Alan

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: IF STATEMENT (Excel 2000)

    When using Or (or And), you must repeat the complete condition:

    If Worksheets(1).Range("F11").Interior.ColorIndex = 6 Or Worksheets(1).Range("F11").Interior.ColorIndex = 4 Or Worksheets(1).Range("F11").Interior.ColorIndex = 5 Or Worksheets(1).Range("F11").Interior.ColorIndex = 3 Or Worksheets(1).Range("F11").Interior.ColorIndex = 39 Or Worksheets(1).Range("F11").Interior.ColorIndex = 7 Then

    As you see, this is very tedious and makes your code hard to read. In such situations, Select Case is more convenient:

    Select Case Worksheets(1).Range("F11").Interior.ColorIndex
    Case 6, 4, 5, 3, 39, 7
    With FrmPressTimeBook.Listtimebooked
    .AddItem "8:00"
    End With
    End Select

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: IF STATEMENT (Excel 2000)

    "Thanks for the support <img src=/S/grin.gif border=0 alt=grin width=15 height=15> " ...<small><post#=525,108>post 525,108</post: ></small> <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Regards,
    Alan

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: IF STATEMENT (Excel 2000)

    Glad to return the service! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  6. #6
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: IF STATEMENT (Excel 2000)

    Thank you guys

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: IF STATEMENT (Excel 2000)

    How many guilders do I owe you then?

    Alan

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: IF STATEMENT (Excel 2000)

    Guilders?

  9. #9
    Star Lounger
    Join Date
    Mar 2001
    Location
    Ontario, Canada
    Posts
    57
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: IF STATEMENT (Excel 2000)

    Sounds like Alan is trying to get rid of some old coins <img src=/S/doze.gif border=0 alt=doze width=15 height=15> But what's the relevance of the 'roo??

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: IF STATEMENT (Excel 2000)


  11. #11
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: IF STATEMENT (Excel 2000)

    Enjoy!

    <IMG SRC=http://www.rosedalemeats.com.au/meatplate.jpg>

    Alan

Posting Permissions

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