PC Review


Reply
Thread Tools Rate Thread

Delete Row if value in row changes

 
 
jscorsone
Guest
Posts: n/a
 
      26th May 2009
I have a workbook with duplicate rows where multiple columns may remain the
same, but column F may change from row to row.

I'm trying to delete all rows that are direct duplicates of the row above it
so I can view just the rows where column F is different (if all other columns
are similar as row above.)

Thanks for any assistance!


 
Reply With Quote
 
 
 
 
Howard31
Guest
Posts: n/a
 
      26th May 2009
Hi there,

Try the following:

Sub DeleteDublicatedRowsAtoE()
Dim Sht As Worksheet
Dim ColsStr1 As String, ColsStr2 As String
Dim LastRow As Long
Dim i As Long

Set Sht = ThisWorkbook.Worksheets("Sheet1")
With Sht
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row


For i = LastRow To 2 Step -1
ColsStr1 = _
.Cells(i, 1) & _
.Cells(i, 2) & _
.Cells(i, 3) & _
.Cells(i, 4) & _
.Cells(i, 5)

ColsStr2 = _
.Cells(i - 1, 1) & _
.Cells(i - 1, 2) & _
.Cells(i - 1, 3) & _
.Cells(i - 1, 4) & _
.Cells(i - 1, 5)

If ColsStr1 = ColsStr2 Then .Rows(i).Delete
Next i
End With
End Sub

"jscorsone" <(E-Mail Removed)> wrote in message
news:1C04C19A-C053-49C7-9566-(E-Mail Removed)...
>I have a workbook with duplicate rows where multiple columns may remain
>the
> same, but column F may change from row to row.
>
> I'm trying to delete all rows that are direct duplicates of the row above
> it
> so I can view just the rows where column F is different (if all other
> columns
> are similar as row above.)
>
> Thanks for any assistance!
>
>


 
Reply With Quote
 
jscorsone
Guest
Posts: n/a
 
      26th May 2009
Thank you so much for the speedy response.

Exactly what I was looking for, thanks again.

"Patrick Molloy" wrote:

> this code removes rows that match for the first 7 columns. No point in
> filter for column "G" as if it differs, it won't be deleted and you'll see
> it anyways
>
> Option Explicit
> Sub removeDupes()
> Dim matched As Boolean
> Dim cl As Long ' column counte
> Dim rw As Long ' row counter
> For rw = 2000 To 2 Step -1
> matched = True
> For cl = 1 To 7
> If Cells(rw, cl) <> Cells(rw - 1, cl) Then
> matched = False
> Exit For
> End If
> Next
> If matched Then
> Rows(rw).Delete
> End If
> Next rw
> End Sub
>
>
>
>
> "jscorsone" <(E-Mail Removed)> wrote in message
> news:1C04C19A-C053-49C7-9566-(E-Mail Removed)...
> > I have a workbook with duplicate rows where multiple columns may remain
> > the
> > same, but column F may change from row to row.
> >
> > I'm trying to delete all rows that are direct duplicates of the row above
> > it
> > so I can view just the rows where column F is different (if all other
> > columns
> > are similar as row above.)
> >
> > Thanks for any assistance!
> >
> >

>

 
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
Delete data in a linked Excel sheet using Access code or seql delete Rocky Microsoft Access External Data 9 26th Jun 2005 12:42 AM
Re: Macro to delete sheets and saves remaining file does not properly delete module gazornenplat Microsoft Excel Programming 0 22nd Jun 2005 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Microsoft Excel Programming 7 21st Jun 2005 05:16 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette Microsoft Excel Programming 2 21st Sep 2004 02:40 PM
Re: When I highlight a sentence to delete, Word won't let me. I have to backspace. How can I deleted selected text with my delete key? Bill Foley Microsoft Word Document Management 1 4th Feb 2004 11:06 PM


Features
 

Advertising
 

Newsgroups
 


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