<\/figure>\n\n\n\nThis example is similar to the previous one, but this time we are going to treat the uppercase\nand lowercase letters the same way.<\/p>\n\n\n\n
It\u2019s very easy to change. At the beginning of your code insert the following line:<\/p>\n\n\n\n
Option Compare Text<\/code><\/pre>\n\n\n\nNow, if you run the code the result will be quite different.<\/p>\n\n\n\n <\/figure>\n\n\n\nIf you don\u2019t want to use Option Compare Text<\/strong>, you can change this line:<\/p>\n\n\n\nIf rng.Item(i).Value = \"delete\" Then<\/code><\/pre>\n\n\n\nTo this one:<\/p>\n\n\n\n
If LCase(rng.Item(i).Value) = LCase(\"delete\") Then<\/code><\/pre>\n\n\n\nIt will change both strings to lowercase while comparing\nvalues.<\/p>\n\n\n\n
If the cell contains the string<\/h2>\n\n\n\n <\/figure>\n\n\n\nThis is the last example. This procedure will remove every row that has the word \u201cdelete\u201d inside. This example is case insensitive.<\/p>\n\n\n\n
Sub DeleteRows()\n Dim rng As Range\n Dim pos As Integer\n Set rng = ActiveSheet.UsedRange\n \n For i = rng.Cells.Count To 1 Step -1\n pos = InStr(LCase(rng.Item(i).Value), LCase(\"delete\"))\n If pos > 0 Then\n rng.Item(i).EntireRow.Delete\n End If\n Next i\nEnd Sub<\/code><\/pre>\n\n\n\nCode explanation:<\/strong><\/p>\n\n\n\nThe InStr<\/strong>\nfunction takes two arguments and returns the position of the first occurrence\nof the word from the second parameter. If the word is not present then it\nreturns 0.<\/p>\n\n\n\nIf the position is greater than 0 then remove the row.<\/p>\n\n\n\n
If you run this code, this is the result you are going to\nget this result.<\/p>\n\n\n\n <\/figure>\n","protected":false},"excerpt":{"rendered":"I\u2019ve already written about removing rows in Excel, that contain specific text. In this lesson, I\u2019ll show you have to achieve this with…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[170,190],"yoast_head":"\n
VBA Delete a Row if the Cell Contains<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n