ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   Macro to delete rows containing specific data (https://www.excelbanter.com/new-users-excel/123236-macro-delete-rows-containing-specific-data.html)

Slohcin

Macro to delete rows containing specific data
 
I have a spreadsheet with the following data in a column:

C100
C101
MTH1
MTH2
R1
R2
TP1
TP2

I wish to delete all rows that contain MTH or TP in that column.
A macro to do this would be great.
--
Thanks
Slohcin

Gary''s Student

Macro to delete rows containing specific data
 
Sub demo()
s1 = "MTH"
s2 = "TP"
For i = 1000 To 1 Step -1
v = Cells(i, "A").Value
If InStr(v, s1) Or InStr(v, s2) Then
Cells(i, "A").EntireRow.Delete
End If
Next
End Sub

This is coded for column A and 1000 rows, adjust as you require.
--
Gary's Student


"Slohcin" wrote:

I have a spreadsheet with the following data in a column:

C100
C101
MTH1
MTH2
R1
R2
TP1
TP2

I wish to delete all rows that contain MTH or TP in that column.
A macro to do this would be great.
--
Thanks
Slohcin


Slohcin

Macro to delete rows containing specific data
 
Thanks Gary, that worked OK.
--
Thanks
Slohcin


"Gary''s Student" wrote:

Sub demo()
s1 = "MTH"
s2 = "TP"
For i = 1000 To 1 Step -1
v = Cells(i, "A").Value
If InStr(v, s1) Or InStr(v, s2) Then
Cells(i, "A").EntireRow.Delete
End If
Next
End Sub

This is coded for column A and 1000 rows, adjust as you require.
--
Gary's Student


"Slohcin" wrote:

I have a spreadsheet with the following data in a column:

C100
C101
MTH1
MTH2
R1
R2
TP1
TP2

I wish to delete all rows that contain MTH or TP in that column.
A macro to do this would be great.
--
Thanks
Slohcin



All times are GMT +1. The time now is 02:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com