ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   I need a macro to delete unwanted data (https://www.excelbanter.com/excel-programming/328083-i-need-macro-delete-unwanted-data.html)

Jason[_36_]

I need a macro to delete unwanted data
 
Hi all,

I need to design a macro in Excel that will delete all unwanted data.
For example: I have fields a,b,c,d. In field c my data is either
x,y,z. If data is y then I want to delete the entire row.

Thanks

Toppers

I need a macro to delete unwanted data
 
Hi,
Something along these lines:

For i = 1 To 3
If Cells(i, "A") = "b" Then Cells(i, "A").EntireRow.Delete
Next


HTH

"Jason" wrote:

Hi all,

I need to design a macro in Excel that will delete all unwanted data.
For example: I have fields a,b,c,d. In field c my data is either
x,y,z. If data is y then I want to delete the entire row.

Thanks


Bob Phillips[_6_]

I need a macro to delete unwanted data
 
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count,"C").End(xlUp).Row
For i = iLastRow to 1 Step -1
If Cells(i,"C").Value = "y" Then
Cells(I,"C").Entirerow.Delete
End If
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jason" wrote in message
om...
Hi all,

I need to design a macro in Excel that will delete all unwanted data.
For example: I have fields a,b,c,d. In field c my data is either
x,y,z. If data is y then I want to delete the entire row.

Thanks




Tom Ogilvy

I need a macro to delete unwanted data
 
Put a b in the first 3 cells and run it. You will find it skips rows. You
need to loop from the highest numbered row to the lowest numbered row.


For i = 3 To 1 Step -1
If Cells(i, "A") = "b" Then Cells(i, "A").EntireRow.Delete
Next

--
Regards,
Tom Ogilvy

"Toppers" wrote in message
...
Hi,
Something along these lines:

For i = 1 To 3
If Cells(i, "A") = "b" Then Cells(i, "A").EntireRow.Delete
Next


HTH

"Jason" wrote:

Hi all,

I need to design a macro in Excel that will delete all unwanted data.
For example: I have fields a,b,c,d. In field c my data is either
x,y,z. If data is y then I want to delete the entire row.

Thanks




Toppers

I need a macro to delete unwanted data
 
Thanks Tom - the number of times you (and others) have told us this !
Hopefully I will remember in future.

"Tom Ogilvy" wrote:

Put a b in the first 3 cells and run it. You will find it skips rows. You
need to loop from the highest numbered row to the lowest numbered row.


For i = 3 To 1 Step -1
If Cells(i, "A") = "b" Then Cells(i, "A").EntireRow.Delete
Next

--
Regards,
Tom Ogilvy

"Toppers" wrote in message
...
Hi,
Something along these lines:

For i = 1 To 3
If Cells(i, "A") = "b" Then Cells(i, "A").EntireRow.Delete
Next


HTH

"Jason" wrote:

Hi all,

I need to design a macro in Excel that will delete all unwanted data.
For example: I have fields a,b,c,d. In field c my data is either
x,y,z. If data is y then I want to delete the entire row.

Thanks





Vasant Nanavati

I need a macro to delete unwanted data
 
IIRC the top-to-bottom approach worked in Excel 95 but the behavior changed
in Excel 97.

--

Vasant

"Toppers" wrote in message
...
Thanks Tom - the number of times you (and others) have told us this !
Hopefully I will remember in future.

"Tom Ogilvy" wrote:

Put a b in the first 3 cells and run it. You will find it skips rows.

You
need to loop from the highest numbered row to the lowest numbered row.


For i = 3 To 1 Step -1
If Cells(i, "A") = "b" Then Cells(i, "A").EntireRow.Delete
Next

--
Regards,
Tom Ogilvy

"Toppers" wrote in message
...
Hi,
Something along these lines:

For i = 1 To 3
If Cells(i, "A") = "b" Then Cells(i, "A").EntireRow.Delete
Next


HTH

"Jason" wrote:

Hi all,

I need to design a macro in Excel that will delete all unwanted

data.
For example: I have fields a,b,c,d. In field c my data is either
x,y,z. If data is y then I want to delete the entire row.

Thanks







Dana DeLouis[_3_]

I need a macro to delete unwanted data
 
Just another similar solution:

For r = 3 To 1 Step -1
If Cells(r, "A") = "b" Then Rows(r).Delete
Next

--
Dana DeLouis
Win XP & Office 2003


"Toppers" wrote in message
...
Thanks Tom - the number of times you (and others) have told us this !
Hopefully I will remember in future.

"Tom Ogilvy" wrote:

Put a b in the first 3 cells and run it. You will find it skips rows.
You
need to loop from the highest numbered row to the lowest numbered row.


For i = 3 To 1 Step -1
If Cells(i, "A") = "b" Then Cells(i, "A").EntireRow.Delete
Next

--
Regards,
Tom Ogilvy

"Toppers" wrote in message
...
Hi,
Something along these lines:

For i = 1 To 3
If Cells(i, "A") = "b" Then Cells(i, "A").EntireRow.Delete
Next


HTH

"Jason" wrote:

Hi all,

I need to design a macro in Excel that will delete all unwanted data.
For example: I have fields a,b,c,d. In field c my data is either
x,y,z. If data is y then I want to delete the entire row.

Thanks







Jason Ward

I need a macro to delete unwanted data
 

Bob Phillips wrote:
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count,"C").End(xlUp).Row
For i = iLastRow to 1 Step -1
If Cells(i,"C").Value = "y" Then
Cells(I,"C").Entirerow.Delete
End If
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jason" wrote in message
om...
Hi all,

I need to design a macro in Excel that will delete all unwanted

data.
For example: I have fields a,b,c,d. In field c my data is either
x,y,z. If data is y then I want to delete the entire row.

Thanks




All times are GMT +1. The time now is 06:40 PM.

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