×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

excel macro

excel macro

excel macro

(OP)
Hi
I am running an excel macro to search for text then delete if found as below. However its also deleting lines with the text "11 order(s)" - is there a way I can specific set to avoid this?


Sub A_Mainsort()

Rows(1).EntireRow.Delete
Rows(1).EntireRow.Delete
Rows(1).EntireRow.Delete
Rows(1).EntireRow.Delete
Rows(1).EntireRow.Delete
Rows(1).EntireRow.Delete
Rows(1).EntireRow.Delete
Rows(1).EntireRow.Delete
Columns("D:I").Delete
Columns("A:C").HorizontalAlignment = xlCenter
Columns("A:C").AutoFit
Dim c As Range
Dim SrchRng
Set SrchRng = ActiveSheet.Range("B1", ActiveSheet.Range("B65536").End(xlUp))
Do
Set c = SrchRng.Find("1 order(s)", LookIn:=xlValues)
If Not c Is Nothing Then c.EntireRow.Delete
Loop While Not c Is Nothing

End Sub

RE: excel macro

You may use optional argument LookAt:=xlWhole in Find method.
Some comments:
1) you can simplify first eight actions with single Rows("1:8").Delete
2) you can use wildcards in Find, esp. when you need exact match, for instance search for "11 order(s)*" if the text has to start with "11 order(s)",
3) if you find nothing, VBA throws error, so except of testing If Not c Is Nothing you need some error handling.

combo

RE: excel macro

(OP)
ok thanks. its just the text 1 order(s) I need it to look for, not different values.
So how would I change my macro to just look for that and not anything else?

RE: excel macro

For exact "1 order(s)" match simply put this as text to search, but with additional LookAt:=xlWhole argument set.

combo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close