Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default 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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default 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






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default 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






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete unwanted data JJ Excel Worksheet Functions 1 February 26th 08 08:14 AM
macro to delete unwanted data pm Excel Discussion (Misc queries) 2 May 2nd 07 06:50 PM
Macro to delete unwanted sheets Sal Excel Discussion (Misc queries) 5 March 15th 07 09:33 PM
Delete Unwanted Data Happy Excel Discussion (Misc queries) 1 August 17th 05 06:20 AM


All times are GMT +1. The time now is 06:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"