Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Operators/if etc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter - 18 Dec 2006 10:39 GMT
Can any one help?!

I am trying to say:
If cell [blah,blah] = Jack or Paddy then cell [blah, blah] should =
Jazz

The code I've got is:

If Cells(40, 1).Value = "Jack" Xor "Paddy" Xor "Andy" Xor "Gary" Then
         Cells(41, 1).Value = "Jazz"
Else
         Cells(41, 1).Value = "Blues"
End If

Needless to say that it doesn't work, so if any of you experts in
google land have any ideas then I'd be very grateful to hear them.

Thanks,

Peter
RichardSchollar - 18 Dec 2006 10:55 GMT
Peter

You could do it with a Select Case structure:

Select Case Cells(40, 1).Value
   Case "Jack", "Paddy", "Andy", "Gary"
       Cells(41, 1) = "Jazz"
   Case Else
       Cells(41, 1) = "Blues"
End Select

If you wanted to use If you'd need to do it like:

If Cells(40,1) = "Jack" Or Cells(40,1) = "Paddy" Or ... etc

which is long-winded.

You don't want to use Xor.

Richard

> Can any one help?!
>
[quoted text clipped - 16 lines]
>
> Peter
james.billy@gmail.com - 18 Dec 2006 10:57 GMT
Hi Peter,

You need to specify the cell again, so your code would be:

If Cells(40, 1).Value = "Jack" Or Cells(40, 1).Value = "Paddy" Or
Cells(40, 1).Value = "Andy" Or Cells(40, 1).Value ="Gary" Then
          Cells(41, 1).Value = "Jazz"
Else
          Cells(41, 1).Value = "Blues"
End If

A more elegant way and possibly an easier way is to use a select
statement, this would look like:

Select Case Cells(40,1).Value
    Case "Jack", "Paddy", "Andy", "Gary"
         Cells(41, 1).Value = "Jazz"
    Case "Peter"
         Cells(41, 1).Value = "R & B"
    Case Else
          Cells(41, 1).Value = "Blues"
End Select

So you select your case in this case Cells(40,1).value and for each
case you are just saying if it equals this then do this, very similar
to an IF statement.

I hope this helps,

James

> Can any one help?!
>
[quoted text clipped - 16 lines]
>
> Peter
Peter - 18 Dec 2006 11:11 GMT
Works like a charm,

Thanks.
Peter - 18 Dec 2006 11:11 GMT
Works like a charm,

Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.