Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Operators/if etc

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 196
Default Operators/if etc

Peter

You could do it with a Select Case structu

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

Peter wrote:
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Operators/if etc

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


Peter wrote:
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Operators/if etc

Works like a charm,

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Operators/if etc

Works like a charm,

Thanks.

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
Where are Bitwise Operators Dennis W. Bulgrien Excel Worksheet Functions 1 June 30th 06 05:51 PM
Comparison Operators Devanath Ong Excel Programming 2 June 22nd 06 03:16 PM
greater than but less than operators for VBA jsr Excel Programming 5 May 27th 06 06:08 PM
Operators With Times Michael Link Excel Discussion (Misc queries) 2 March 9th 05 02:46 PM
Unary operators Joe Excel Worksheet Functions 3 February 14th 05 06:09 PM


All times are GMT +1. The time now is 08:09 AM.

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

About Us

"It's about Microsoft Excel"