#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default better way

Hi, is ther a better way of writing this.
If r = "K" And i = 2 Or r = "Q" And i = 2 Or r = "J" And i = 2 Then
r1 = 10 + i
y = i
x = 112
end if.

As you can see i always = 2 but r can be a k,q, or j. This way works
perfect, just thinking that there may be a better way. I was thinking
something like if r = k/q/j.
regards Robert

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default better way

If i=2 And InStr("KQJ",r)0 Then
r1=....
etc
End If

NickHK

wrote in message
oups.com...
Hi, is ther a better way of writing this.
If r = "K" And i = 2 Or r = "Q" And i = 2 Or r = "J" And i = 2 Then
r1 = 10 + i
y = i
x = 112
end if.

As you can see i always = 2 but r can be a k,q, or j. This way works
perfect, just thinking that there may be a better way. I was thinking
something like if r = k/q/j.
regards Robert



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default better way

Hello,

NickHK wrote:
If i=2 And InStr("KQJ",r)0 Then


Sorry, that's more than the OP wants. This is TRUE for r="K", "Q", "J",
"KQ", "QJ" and "KQJ" (and i=2, of course)

Regards,
Bernd

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default better way

Depends what are possible values for r.
If i=2 And InStr("KQJ",Left(r,1))0 Then

Better.

NickHK

wrote in message
ups.com...
Hello,

NickHK wrote:
If i=2 And InStr("KQJ",r)0 Then


Sorry, that's more than the OP wants. This is TRUE for r="K", "Q", "J",
"KQ", "QJ" and "KQJ" (and i=2, of course)

Regards,
Bernd



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default better way

Hello,

Sorry, no. This would accept any r starting with "K", "Q" or "J" (i
being 2).

Maybe
If i = 2 And Application.WorksheetFunction.Match(r, _
Array("K", "Q", "J", r), False) < 4 Then
...
End If

or just

If i=2 and (r="K" or r="Q" or r="J") then
...
end if


Regards,
Bernd



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default better way

Thankyou for your replys. I trying both ideas.
Regards Robert

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



All times are GMT +1. The time now is 12:33 AM.

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

About Us

"It's about Microsoft Excel"