deleting rows

paulsolar

Well-known Member
Joined
Aug 21, 2013
Messages
682
Office Version
  1. 365
Hi

I'm having a bad day today :confused:

I want to delete rows where column V contains a variable text

I normally use
For i = Selection.Rows.Count To 1 Step -1
If Cells(i, 22).Value = "???????" Then ' the question marks are what I want to remove
Cells(i, 22).EntireRow.Delete
End If
Next i

What I actually want to do is remove any rows where the data in column V starts with HS-

cheers

Paul
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
How big is your data?

BTW, you still have not updated your version details. ;)
 
Upvote 0
Where do i update my version data please?
As I advised here.


3 or 400 rows
OK, then try this
VBA Code:
Sub DelRws()
  Dim i As Long
 
  Application.ScreenUpdating = False
    For i = Range("V" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Cells(i, "V").Value Like "HS-*" Then Rows(i).Delete
    Next i
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
As I advised here.



OK, then try this
VBA Code:
Sub DelRws()
  Dim i As Long
 
  Application.ScreenUpdating = False
    For i = Range("V" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Cells(i, "V").Value Like "HS-*" Then Rows(i).Delete
    Next i
  Application.ScreenUpdating = True
End Sub
it doesnt appear to be working,
 
Upvote 0
Thanks for updating your details. (y)

it doesnt appear to be working,
That gives us nothing to go on. ;)
Did it ..
  • Crash Excel?
  • Give an error message? (What message on what line?)
  • Delete the wrong rows? (Details)
  • Do nothing?
  • Something else?

Given that it worked for what I understood your data was like, it is likely your data and my sample data are different in some way.
Here is mine before the code was run

paulsolar.xlsm
V
1Heading
2abc
3HS-sad
4xyz
5HS-vsdf
6HS-
7HS-HS-
8HSV
9zzz
10
11yyy
Sheet1


After

paulsolar.xlsm
V
1Heading
2abc
3xyz
4HSV
5zzz
6
7yyy
8
Sheet1


Do I have inappropriate sample data?
Perhaps you could give us a similarly small set of representative sample of your data (any sensitive information disguised or removed) with XL2BB so that we can easily test with appropriate data?
 
Upvote 0
Sorry if I'm off here and don't understand the issue, but give this a shot. It's a small change to your original code.
VBA Code:
For i = Selection.Rows.Count To 1 Step -1
If Left(Cells(i, 22).Value,3) = "HS-" Then ' the question marks are what I want to remove
Cells(i, 22).EntireRow.Delete
End If
Next i
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

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