Wildcard in VBA?

R

richzip

I apologize if this is here twice--I don't see the post I thought went
through earlier today. Anyway ..

I have the following code:

If .Cells(X, "H") = "RG" Then
.Cells(X, "G").Value = "TRC"
End If

Can I modify this with a "wildcard" character? In other words, if RG is
found anywhere (RG123, RG456, 123RG, etc) within cell H, I want TRC to be
placed into column G

Thanks!
 
G

Gary Keramidas

maybe something like this, i just hard coded the variable for testing

Sub test()
Dim x As Long
x = 3

If Cells(x, "H") Like "?G" Then
Cells(x, "G").Value = "TRC"
End If

End Sub
 
R

Rick Rothstein

Given what the OP posted, I believe your Like operator test should be this...

If Cells(x, "H") Like "*RG*" Then

That would be a case sensitive test; if the OP need a non-case sensitive test, that would look like this...

If Cells(x, "H") Like "*[Rr][Gg]*" Then
 
G

Gary Keramidas

yea, i missed this part (RG123, RG456, 123RG).
i guess i should read the entire post<g>

--


Gary Keramidas
Excel 2003


Given what the OP posted, I believe your Like operator test should be this...

If Cells(x, "H") Like "*RG*" Then

That would be a case sensitive test; if the OP need a non-case sensitive test,
that would look like this...

If Cells(x, "H") Like "*[Rr][Gg]*" Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top