PC Review


Reply
Thread Tools Rate Thread

delete duplicate data

 
 
=?Utf-8?B?U0lUQ0ZhblRO?=
Guest
Posts: n/a
 
      4th Jun 2006
Can Somebody please explain this code to me? I think it may meet my needs
but I'm just not sure. I want to delete the previous row if the data in
column G is the same in 2 consecutive rows.

Sub deleledupsinpreviousrows()
For i = Cells(Rows.Count, "a").End(xlUp).Row To 2 Step -1
If Cells(i - 1, 1) = Cells(i, 1) Then Rows(i - 1).Delete
Next
End Sub

 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      4th Jun 2006
Hi SITCFanTN,

Your code operates on duplicates in column A of the active sheet. Try the
following minor adaptation:

'=============>>
Sub DeleleDupesInPreviousRows()
Dim WB As Workbook
Dim SH As Worksheet
Dim i As Long
Const col As String = "G" '<<==== CHANGE

Set WB = Workbooks("YourBook.xls") '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

With SH
For i = .Cells(Rows.Count, col).End(xlUp).Row To 2 Step -1
If .Cells(i - 1, col) = .Cells(i, col) Then
.Rows(i - 1).Delete
End If
Next
End With

End Sub
'<<=============

---
Regards,
Norman


"SITCFanTN" <(E-Mail Removed)> wrote in message
news1B6B790-6F66-4C84-AC97-(E-Mail Removed)...
> Can Somebody please explain this code to me? I think it may meet my needs
> but I'm just not sure. I want to delete the previous row if the data in
> column G is the same in 2 consecutive rows.
>
> Sub deleledupsinpreviousrows()
> For i = Cells(Rows.Count, "a").End(xlUp).Row To 2 Step -1
> If Cells(i - 1, 1) = Cells(i, 1) Then Rows(i - 1).Delete
> Next
> End Sub
>



 
Reply With Quote
 
=?Utf-8?B?U0lUQ0ZhblRO?=
Guest
Posts: n/a
 
      4th Jun 2006
Thanks so much Norman, one more question for you. Since I will be running
this code in a macro that is launched by clicking on an icon on the toolbar
that I have created, do I have to specify the Workbook and worksheet in the
code?

Thanks so much.

Joyce

"Norman Jones" wrote:

> Hi SITCFanTN,
>
> Your code operates on duplicates in column A of the active sheet. Try the
> following minor adaptation:
>
> '=============>>
> Sub DeleleDupesInPreviousRows()
> Dim WB As Workbook
> Dim SH As Worksheet
> Dim i As Long
> Const col As String = "G" '<<==== CHANGE
>
> Set WB = Workbooks("YourBook.xls") '<<==== CHANGE
> Set SH = WB.Sheets("Sheet1") '<<==== CHANGE
>
> With SH
> For i = .Cells(Rows.Count, col).End(xlUp).Row To 2 Step -1
> If .Cells(i - 1, col) = .Cells(i, col) Then
> .Rows(i - 1).Delete
> End If
> Next
> End With
>
> End Sub
> '<<=============
>
> ---
> Regards,
> Norman
>
>
> "SITCFanTN" <(E-Mail Removed)> wrote in message
> news1B6B790-6F66-4C84-AC97-(E-Mail Removed)...
> > Can Somebody please explain this code to me? I think it may meet my needs
> > but I'm just not sure. I want to delete the previous row if the data in
> > column G is the same in 2 consecutive rows.
> >
> > Sub deleledupsinpreviousrows()
> > For i = Cells(Rows.Count, "a").End(xlUp).Row To 2 Step -1
> > If Cells(i - 1, 1) = Cells(i, 1) Then Rows(i - 1).Delete
> > Next
> > End Sub
> >

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      4th Jun 2006
You can either specify the workbook and worksheet or you can assume that the
user is running the code against the activesheet and just use that.

If you use the Activesheet, then you wouldn't need the WB variable and this
portion:

> > Set WB = Workbooks("YourBook.xls") '<<==== CHANGE
> > Set SH = WB.Sheets("Sheet1") '<<==== CHANGE
> >
> > With SH


Becomes


> > Set SH = ActiveSheet
> >
> > With SH


SITCFanTN wrote:
>
> Thanks so much Norman, one more question for you. Since I will be running
> this code in a macro that is launched by clicking on an icon on the toolbar
> that I have created, do I have to specify the Workbook and worksheet in the
> code?
>
> Thanks so much.
>
> Joyce
>
> "Norman Jones" wrote:
>
> > Hi SITCFanTN,
> >
> > Your code operates on duplicates in column A of the active sheet. Try the
> > following minor adaptation:
> >
> > '=============>>
> > Sub DeleleDupesInPreviousRows()
> > Dim WB As Workbook
> > Dim SH As Worksheet
> > Dim i As Long
> > Const col As String = "G" '<<==== CHANGE
> >
> > Set WB = Workbooks("YourBook.xls") '<<==== CHANGE
> > Set SH = WB.Sheets("Sheet1") '<<==== CHANGE
> >
> > With SH
> > For i = .Cells(Rows.Count, col).End(xlUp).Row To 2 Step -1
> > If .Cells(i - 1, col) = .Cells(i, col) Then
> > .Rows(i - 1).Delete
> > End If
> > Next
> > End With
> >
> > End Sub
> > '<<=============
> >
> > ---
> > Regards,
> > Norman
> >
> >
> > "SITCFanTN" <(E-Mail Removed)> wrote in message
> > news1B6B790-6F66-4C84-AC97-(E-Mail Removed)...
> > > Can Somebody please explain this code to me? I think it may meet my needs
> > > but I'm just not sure. I want to delete the previous row if the data in
> > > column G is the same in 2 consecutive rows.
> > >
> > > Sub deleledupsinpreviousrows()
> > > For i = Cells(Rows.Count, "a").End(xlUp).Row To 2 Step -1
> > > If Cells(i - 1, 1) = Cells(i, 1) Then Rows(i - 1).Delete
> > > Next
> > > End Sub
> > >

> >
> >
> >


--

Dave Peterson
 
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
VBA to delete Duplicate Records (1 column), before which, non-duplicate data merged into remaining row EagleOne@discussions.microsoft.com Microsoft Excel Programming 6 20th Aug 2009 02:40 AM
Re: Delete duplicate data based on date of data Phillip Microsoft Excel Programming 1 24th Jan 2007 05:55 PM
delete duplicate data in the same cell elaine Microsoft Excel Programming 6 13th Dec 2006 04:55 PM
How to delete duplicate data =?Utf-8?B?UEw=?= Microsoft Excel New Users 9 1st Sep 2006 03:47 AM
Delete duplicate data. Leo Leong Microsoft Excel Misc 1 18th Sep 2003 01:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:25 PM.