Delete row question

jamespatrick

New Member
Joined
Sep 21, 2010
Messages
24
Hello,

Any help with this question would be greatly appreciated as I am a bit of an excel amateur!

Is it possible to delete rows that do not match a stated reference number? Basically I have 2 columns, ref no. and name and I only want to show names that match a reference number. Here is the difficult part the ref no. is a 4 digit number followed by a letter and it is the letter that I need to match.

eg : Ref No. Name
1232A James
4242P John
2434C Steve
5453P Jack

I only want to show ref no.s ending in P which is John and jack. Is it possible to only show these rows?

Thanks

James
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
You could add a helper column and put this formula in it...

=RIGHT(A2)

and copy it down, then AutoFilter on that helper column.
 
Upvote 0
Hi James,
Try this out on a sample of your data.

Code:
Option Explicit
Sub PKeeper()
Dim LRow1 As Long
Dim rngC As Range
With Sheets("Sheet1")
  LRow1 = .Cells(.Rows.Count, 2).End(xlUp).Row
    For Each rngC In .Range("B2:B" & LRow1)
      If rngC.Value = Left$(rngC, 4) <> "P" Then
        rngC.EntireRow.Delete
      End If
    Next
End With
End Sub

Regards,
Howard
 
Upvote 0
Great,

Thanks for the solutions, I love the simplicity of the helper column that works great and I didn't realize about the right command. I will try out the code and let you know how I get on.

Thanks again

James
 
Upvote 0
You are welcome, and Rick's advice is pretty much a gold standard. Can't go wrong there.

Howard
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,082
Members
449,205
Latest member
Healthydogs

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