How can i do this like in VBA

Siyanna

Well-known Member
Joined
Nov 7, 2011
Messages
1,146
Hi all,

how can i have multiple like criterias?

i.e

if cell.value like ??? Or ??? Or ??? Etc...

rather than writing the like statement multiple times

something like this. Like{aaa,bbb,ddd,fff} etc....

Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Code:
Select Case cell.Value


Case "aaa", "bbb", "ddd", "fff"
'your code here


Case "ccc", "eee"
'your code here


End Select
 
Upvote 0
Code:
Select Case cell.Value


Case "aaa", "bbb", "ddd", "fff"
'your code here


Case "ccc", "eee"
'your code here


End Select
hi thank u

wat if i wanted the wild card character
*aa* so anything before and after aa? Etc
 
Upvote 0
Hi all,

how can i have multiple like criterias?

i.e

if cell.value like ??? Or ??? Or ??? Etc...

rather than writing the like statement multiple times

something like this. Like{aaa,bbb,ddd,fff} etc....

Thanks
As far as I know there isn't a way to do it as concisely as you are indicating. However, if you were a bit more specific about just what you have and what you are trying to achieve, some other suggestions might come along.
 
Upvote 0
Hi Peter

all it was that i wanted to search for a text strings but it could have text before it so i wondered if i can do a multiple search like criteria

if cell.value like "*aa" or "*bb" etc...
 
Upvote 0
Hi Peter

all it was that i wanted to search for a text strings but it could have text before it so i wondered if i can do a multiple search like criteria

if cell.value like "*aa" or "*bb" etc...
Yes, I understood that, and I have answered that as best I can.

However, my answer wouldn't have helped you so I'm trying to get you to be specific to see if I might be able to help.

For example, does 'etc' mean you have a total of 3 strings to compare or 300?
How long are the actual strings you are looking for?
Are there any patterns in the strings?
Could you give some examples of the actual strings you are searching for? (I'm assuming you are not actually searching for 'aaa', 'bbb', 'ddd' & 'fff')
How many cells are you going to look for these strings in?

I'm just trying to get an understanding of what you actually have and are actually trying to achieve.
 
Upvote 0
Does the text strings you want to search for have anything consistant between them? For example the following is snipped from a recent macro I created (with some help from this forum):
Code:
    Dim I As Integer
    Dim Pos As Integer
    Dim FindChar As String
    Dim SearchString As String

    For A = 1 To 254                                      'TEXAS HAS 254 COUNTIES
         R = "D" & A
         j = "a" & A
         C = "c" & A
         SearchString = Sheet1.Range(j)
         FindChar = " "
         For I = 1 To Len(SearchString)
             If Mid(SearchString, I, 1) = FindChar Then Pos = I
         Next I
         Sheet1.Range(R) = UCase(Left$(SearchString, Pos))
         Sheet1.Range(C) = A
    Next A

but I knew what character I was looking for. It was two words seperated by a space but the length of the first word varried. Do you know what you are looking for?
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,892
Members
449,058
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top