PC Review


Reply
Thread Tools Rate Thread

Delete Rows on Set Criteria

 
 
Sue
Guest
Posts: n/a
 
      17th Oct 2008
Hi All

An easy one for all you experts

I need a macro to delete the all the rows on the active sheet if in Column F
/ Row5 the values in all the cells in Column F do not match the value in
Column F / Row5
--
Many Thanks

Sue
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      17th Oct 2008
Sue,

That doesn't make sense, what are we comparing Column F to

Mike

"Sue" wrote:

> Hi All
>
> An easy one for all you experts
>
> I need a macro to delete the all the rows on the active sheet if in Column F
> / Row5 the values in all the cells in Column F do not match the value in
> Column F / Row5
> --
> Many Thanks
>
> Sue

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      17th Oct 2008
All the cells in Row F? Do you mean all 256 in Excel 2003 and who knows
how many in 2007? Or are you just talking about the cells in the UsedRange?

Barb Reinhardt

"Sue" wrote:

> Hi All
>
> An easy one for all you experts
>
> I need a macro to delete the all the rows on the active sheet if in Column F
> / Row5 the values in all the cells in Column F do not match the value in
> Column F / Row5
> --
> Many Thanks
>
> Sue

 
Reply With Quote
 
Shasur
Guest
Posts: n/a
 
      17th Oct 2008
Hi Sue

Which two sheets are you comparing ?

Here is a hint

Sub Delete_Rows_ForSue()


Dim iRow
Dim iMaxRow

iMaxRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
For iRow = 1 To iMaxRow
If iRow > iMaxRow Then Exit Sub
If ActiveSheet.Cells(iRow, 6) <> Sheets(2).Cells(iRow, 6) Then
Rows(iRow).EntireRow.Delete
iRow = iRow - 1
iMaxRow = iMaxRow - 1
End If
NoDelete:
Next iRow
End Sub

Cheers
Shasur
--
http://vbadud.blogspot.com


"Sue" wrote:

> Hi All
>
> An easy one for all you experts
>
> I need a macro to delete the all the rows on the active sheet if in Column F
> / Row5 the values in all the cells in Column F do not match the value in
> Column F / Row5
> --
> Many Thanks
>
> Sue

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      17th Oct 2008
I bet you never tested this

"Shasur" wrote:

> Hi Sue
>
> Which two sheets are you comparing ?
>
> Here is a hint
>
> Sub Delete_Rows_ForSue()
>
>
> Dim iRow
> Dim iMaxRow
>
> iMaxRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
> For iRow = 1 To iMaxRow
> If iRow > iMaxRow Then Exit Sub
> If ActiveSheet.Cells(iRow, 6) <> Sheets(2).Cells(iRow, 6) Then
> Rows(iRow).EntireRow.Delete
> iRow = iRow - 1
> iMaxRow = iMaxRow - 1
> End If
> NoDelete:
> Next iRow
> End Sub
>
> Cheers
> Shasur
> --
> http://vbadud.blogspot.com
>
>
> "Sue" wrote:
>
> > Hi All
> >
> > An easy one for all you experts
> >
> > I need a macro to delete the all the rows on the active sheet if in Column F
> > / Row5 the values in all the cells in Column F do not match the value in
> > Column F / Row5
> > --
> > Many Thanks
> >
> > Sue

 
Reply With Quote
 
Sue
Guest
Posts: n/a
 
      17th Oct 2008
Hi

My mistake

I should have stipulated the used range

and in Column F / Row 5 there is a number and if any cell in the used range
in Column F does not match that number then the row is deleted
--
Many Thanks

Sue


"Barb Reinhardt" wrote:

> All the cells in Row F? Do you mean all 256 in Excel 2003 and who knows
> how many in 2007? Or are you just talking about the cells in the UsedRange?
>
> Barb Reinhardt
>
> "Sue" wrote:
>
> > Hi All
> >
> > An easy one for all you experts
> >
> > I need a macro to delete the all the rows on the active sheet if in Column F
> > / Row5 the values in all the cells in Column F do not match the value in
> > Column F / Row5
> > --
> > Many Thanks
> >
> > Sue

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      17th Oct 2008
A better way would be

For iRow = iMaxRow to 1 step -1

And don't update iRow or iMaxRow later.

Barb Reinhardt



"Shasur" wrote:

> Hi Sue
>
> Which two sheets are you comparing ?
>
> Here is a hint
>
> Sub Delete_Rows_ForSue()
>
>
> Dim iRow
> Dim iMaxRow
>
> iMaxRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
> For iRow = 1 To iMaxRow
> If iRow > iMaxRow Then Exit Sub
> If ActiveSheet.Cells(iRow, 6) <> Sheets(2).Cells(iRow, 6) Then
> Rows(iRow).EntireRow.Delete
> iRow = iRow - 1
> iMaxRow = iMaxRow - 1
> End If
> NoDelete:
> Next iRow
> End Sub
>
> Cheers
> Shasur
> --
> http://vbadud.blogspot.com
>
>
> "Sue" wrote:
>
> > Hi All
> >
> > An easy one for all you experts
> >
> > I need a macro to delete the all the rows on the active sheet if in Column F
> > / Row5 the values in all the cells in Column F do not match the value in
> > Column F / Row5
> > --
> > Many Thanks
> >
> > Sue

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      17th Oct 2008
If you have col f with
f1
f2
f3
f4
f5 10
f6 4
f7 5
f8 10
f9 6
f10 10
and you want to delete row 8 and row 10, then this will do it

for i = 10 to 6 step -1
if cells(i,"f")=cells(5,"f") then rows(i).delete
next i

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Sue" <(E-Mail Removed)> wrote in message
news:1E2804B2-AC9F-45B9-8415-(E-Mail Removed)...
> Hi
>
> My mistake
>
> I should have stipulated the used range
>
> and in Column F / Row 5 there is a number and if any cell in the used
> range
> in Column F does not match that number then the row is deleted
> --
> Many Thanks
>
> Sue
>
>
> "Barb Reinhardt" wrote:
>
>> All the cells in Row F? Do you mean all 256 in Excel 2003 and who
>> knows
>> how many in 2007? Or are you just talking about the cells in the
>> UsedRange?
>>
>> Barb Reinhardt
>>
>> "Sue" wrote:
>>
>> > Hi All
>> >
>> > An easy one for all you experts
>> >
>> > I need a macro to delete the all the rows on the active sheet if in
>> > Column F
>> > / Row5 the values in all the cells in Column F do not match the value
>> > in
>> > Column F / Row5
>> > --
>> > Many Thanks
>> >
>> > Sue


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      17th Oct 2008
Maybe

Sub copyit()
Dim MyRange, MyRange1 As Range, DeleteRange As Range
myvalue = Range("F5").Value
lastrow = Cells(Rows.Count, "F").End(xlUp).Row
Set MyRange = Range("F6:F" & lastrow)
For Each c In MyRange
If c.Value <> myvalue Then
If DeleteRange Is Nothing Then
Set DeleteRange = c.EntireRow
Else
Set DeleteRange = Union(DeleteRange, c.EntireRow)
End If

End If
Next
If Not DeleteRange Is Nothing Then
DeleteRange.Delete
End If
End Sub

Mike

"Sue" wrote:

> Hi
>
> My mistake
>
> I should have stipulated the used range
>
> and in Column F / Row 5 there is a number and if any cell in the used range
> in Column F does not match that number then the row is deleted
> --
> Many Thanks
>
> Sue
>
>
> "Barb Reinhardt" wrote:
>
> > All the cells in Row F? Do you mean all 256 in Excel 2003 and who knows
> > how many in 2007? Or are you just talking about the cells in the UsedRange?
> >
> > Barb Reinhardt
> >
> > "Sue" wrote:
> >
> > > Hi All
> > >
> > > An easy one for all you experts
> > >
> > > I need a macro to delete the all the rows on the active sheet if in Column F
> > > / Row5 the values in all the cells in Column F do not match the value in
> > > Column F / Row5
> > > --
> > > Many Thanks
> > >
> > > Sue

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      17th Oct 2008
See my post

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Shasur" <(E-Mail Removed)> wrote in message
news:7D03ED67-0BD6-45DA-A604-(E-Mail Removed)...
> Hi Sue
>
> Which two sheets are you comparing ?
>
> Here is a hint
>
> Sub Delete_Rows_ForSue()
>
>
> Dim iRow
> Dim iMaxRow
>
> iMaxRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
> For iRow = 1 To iMaxRow
> If iRow > iMaxRow Then Exit Sub
> If ActiveSheet.Cells(iRow, 6) <> Sheets(2).Cells(iRow, 6) Then
> Rows(iRow).EntireRow.Delete
> iRow = iRow - 1
> iMaxRow = iMaxRow - 1
> End If
> NoDelete:
> Next iRow
> End Sub
>
> Cheers
> Shasur
> --
> http://vbadud.blogspot.com
>
>
> "Sue" wrote:
>
>> Hi All
>>
>> An easy one for all you experts
>>
>> I need a macro to delete the all the rows on the active sheet if in
>> Column F
>> / Row5 the values in all the cells in Column F do not match the value in
>> Column F / Row5
>> --
>> Many Thanks
>>
>> Sue


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable criteria to delete rows =?Utf-8?B?SmVmZiBCZXJ0cmFt?= Microsoft Excel Programming 18 21st Jul 2008 07:30 PM
Delete Rows that fit a certain criteria =?Utf-8?B?anBpdHRhcmk=?= Microsoft Excel Programming 3 2nd Nov 2007 03:22 PM
Delete rows with different criteria =?Utf-8?B?Sm9obg==?= Microsoft Excel Programming 7 13th Jul 2005 05:38 PM
delete rows with criteria S.E. Microsoft Excel Programming 5 9th Sep 2004 04:04 PM
Delete rows w/o criteria RickK Microsoft Excel Programming 2 31st Oct 2003 04:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:13 PM.