optimize if with range(vba for excel)

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

optimize if with range(vba for excel)

Post by sal21 »

Actually have

Code: Select all

If Mid(TEST, 12, 19) = "OPERAZIONE ESEGUITA" And new condition Then
in new condition i want to set a series of values

how to?

note:
the series of avlue are in a column A of sheet1

similar:
aa
cc
vv
ff
gg
...
tt

User avatar
HansV
Administrator
Posts: 78457
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: optimize if with range(vba for excel)

Post by HansV »

Please explain what you mean by "i want to set a series of values".
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: optimize if with range(vba for excel)

Post by sal21 »

HansV wrote:Please explain what you mean by "i want to set a series of values".
Instead
If Mid(TEST, 12, 19) = "OPERAZIONE ESEGUITA" or cod="aa" or cod="cc" or cod="vv".... then

User avatar
HansV
Administrator
Posts: 78457
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: optimize if with range(vba for excel)

Post by HansV »

You could do it like this:

Code: Select all

If Mid(TEST, 12, 19) =  "OPERAZIONE ESEGUITA" Then
  Select Case cod
    Case "aa", "cc", "vv", "ff", "gg", ..., "tt"
      ' code here for when cod is one of the above values
    Case Else
      ' code here for when cod is NOT one of the above values
  End Select
End If
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: optimize if with range(vba for excel)

Post by sal21 »

HansV wrote:You could do it like this:

Code: Select all

If Mid(TEST, 12, 19) =  "OPERAZIONE ESEGUITA" Then
  Select Case cod
    Case "aa", "cc", "vv", "ff", "gg", ..., "tt"
      ' code here for when cod is one of the above values
    Case Else
      ' code here for when cod is NOT one of the above values
  End Select
End If
TKS!