delete rows with specific text amend current code to pick up upper or lower case

matklt

New Member
Joined
Oct 14, 2016
Messages
5
I have the following code that basically searches column O and deletes any rows that contain the words in the array. Only problem is it wont remove rows where the words have capitals in or vice versa. I have lots of keywords to search for so adding different versions of each word isn't an option

Code:
Sub DelRows()
Dim V As Variant, DeleteMe As Variant
DeleteMe = Array("suma", "screw")
For Each V In DeleteMe
 Columns("O").Replace "*" & V & "*", "#N/A", xlWhole, , True, False, False
Next
On Error Resume Next
 Columns("O").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
On Error GoTo 0

End Sub
 

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,561
This isn't a full solution, but it may steer you in the right direction. Using "UCase" you can convert everything in a string to upper case, then do the replace task. This code converts everything in your array to uppercase, so works on text in the "O" column which is ALL upper case, but so far I can't see how to get the col O values to upper case, so it's still not working on anything in col O which is only PARTLY upper case...
Code:
Sub DelRows()
Dim V As Variant, DeleteMe As Variant
Dim cl As Range
Dim rng As Range

Set rng = ActiveSheet.Columns("O")
DeleteMe = Array("suma", "screw")

For Each V In DeleteMe
 Columns("O").Replace "*" & UCase(V) & "*", "#N/A", xlWhole, , True, False, False

Next
On Error Resume Next
 Columns("O").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
On Error GoTo 0

End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,531
Office Version
365
Platform
Windows
Try
Code:
 Columns("O").Replace "*" & V & "*", "#N/A", xlWhole, , [COLOR=#ff0000]False, ,[/COLOR] False, False
You had match case set to True, rather than False.
You where also missing an extra coma.
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,531
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,078,447
Messages
5,340,344
Members
399,370
Latest member
salamon

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top