# Solved: Excel 2003 Like Operator

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

#### computerman29642

Does anyone know how to use the LIKE operator in an Excel macro? As far as I know, wildcards cannot be used in an Excel macro, so I thought the next best thing would be the LIKE operator.

What I am trying to do is take the following code....

Code:
``````For r = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If Cells(r, 1) = "" Then Rows(r).Delete
Next r``````
Instead of it deleting rows that are blank, I was hoping change the following line:

Code:
``If Cells(r, 1) = "" Then Rows(r).Delete``
TO

Code:
``````If Cells(r, 1) = LIKE(ac) OR Like(Sample)  Then
'Do Nothing
Else
Rows(r).Delete``````
If anyone has any suggestions, they will be greatly appreciated.

#### Ziggy1

take the equals out before LIKE, and use quotes around the text to compare. You need the wildards for it to work

Public Sub test()

Dim x As Integer

For x = 1 To 10

If Range("A" & x).Value Like ("AC*") Or Range("A" & x).Value Like ("SAMPLE") Then

Else

Rows(x).Delete

End If

Next

End Sub

#### computerman29642

Ziggy,

Thank you for the reply. I will give a shot, and let you know how it works.

#### Ziggy1

actually I should have put it the way you had...

Code:
``````Public Sub test2()

For r = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1

If Cells(r, 1) Like ("AC*") Or Cells(r, 1) Like ("SAMPLE") Then

Else

Rows(r).Delete

End If

Next r

End Sub``````

#### computerman29642

This works great. Thanks very much Ziggy.

np

#### Zack Barresse

hi Chris. Is this like the issue we were discussing on your workbook the other day and the formulas which evaluate to null? if so, we'll be able to work with this with the dynamic range of formulas and not need an expensive loop. Try to stay away from loops like we were talking about. I'll await your response for further.

Sent via mobile device.

#### computerman29642

Zack,

Yes & No. The code I was asking about here does not really tie in with the workbook, but I needed it to setup a file that will be copied into the workbook. The machine that created the file places a lot of extra lines and headers that are not needed.

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

As Seen On

### Welcome to Tech Support Guy!

If you're not already familiar with forums, watch our Welcome Guide to get started.

over 807,865 other people just like you!