Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Delete if Three Matches in Three Columns

I am trying to loop through a data set (sorted by ColumnD, ColumnF, and
ColumnG), and trying to delete dupes in ColumnD, ColumnF, and ColumnG.


'Compare and delete if dupes
Dim rCell As Range
With ActiveSheet
For Each rCell In .Range("D1:D" & _
.Range("D" & .Rows.Count).End(xlUp).Row)
With rCell
If .Value = .Offset(0, 2).Value Then
If .Value = .Offset(0, 3).Value Then
rCell.EntireRow.Delete
Else
End If
End If
End With
Next rCell
End With

The dupes arent deleted and I know I have to delete from the bottom up€¦but
I dont think my code is doing that now. How can I change this to work
correctly?

Thanks,
Ryan---


--
RyGuy
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Delete if Three Matches in Three Columns

Well, thanks Don! That looks pretty sexy, but it didn't work as it was. I
made a few minor changes, and still no luck. Working with this now:

For i = Cells(Rows.Count, 4).End(xlUp).Row To 2 Step -1
If Cells(i, 6) And Cells(i, 7) = Cells(i, 4) Then
Rows(i).Delete
End If
Next i

I get a Run-time Error 13; type mismatch.
Any ideas?

Thanks,
Ryan---

--
RyGuy


"Don Guillett" wrote:

try this
Sub deleltedupcolumns()
For i = Cells(Rows.Count, "d").End(xlUp).Row To 2 Step -1
If Cells(i, "e") = Cells(i, "d") And Cells(i, "f") = Cells(i, "d") Then
Rows(i).Delete
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"ryguy7272" wrote in message
...
I am trying to loop through a data set (sorted by ColumnD, ColumnF, and
ColumnG), and trying to delete dupes in ColumnD, ColumnF, and ColumnG.


'Compare and delete if dupes
Dim rCell As Range
With ActiveSheet
For Each rCell In .Range("D1:D" & _
.Range("D" & .Rows.Count).End(xlUp).Row)
With rCell
If .Value = .Offset(0, 2).Value Then
If .Value = .Offset(0, 3).Value Then
rCell.EntireRow.Delete
Else
End If
End If
End With
Next rCell
End With

The dupes arent deleted and I know I have to delete from the bottom
up€¦but
I dont think my code is doing that now. How can I change this to work
correctly?

Thanks,
Ryan---


--
RyGuy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Delete if Three Matches in Three Columns

Worked for me, AS TESTED, except for the email word wrap on the THEN. Excel
wants it this way
If Cells(i, "e") = Cells(i, "d") And Cells(i, "f") = Cells(i, "d") Then
or
If Cells(i, 6 = Cells(i, 4 )and Cells(i, 7) = Cells(i, 4) Then

Don Guillett
Microsoft MVP Excel
SalesAid Software

"ryguy7272" wrote in message
...
Well, thanks Don! That looks pretty sexy, but it didn't work as it was.
I
made a few minor changes, and still no luck. Working with this now:

For i = Cells(Rows.Count, 4).End(xlUp).Row To 2 Step -1
If Cells(i, 6) And Cells(i, 7) = Cells(i, 4) Then
Rows(i).Delete
End If
Next i

I get a Run-time Error 13; type mismatch.
Any ideas?

Thanks,
Ryan---

--
RyGuy


"Don Guillett" wrote:

try this
Sub deleltedupcolumns()
For i = Cells(Rows.Count, "d").End(xlUp).Row To 2 Step -1
If Cells(i, "e") = Cells(i, "d") And Cells(i, "f") = Cells(i, "d") Then
Rows(i).Delete
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"ryguy7272" wrote in message
...
I am trying to loop through a data set (sorted by ColumnD, ColumnF, and
ColumnG), and trying to delete dupes in ColumnD, ColumnF, and ColumnG.


'Compare and delete if dupes
Dim rCell As Range
With ActiveSheet
For Each rCell In .Range("D1:D" & _
.Range("D" & .Rows.Count).End(xlUp).Row)
With rCell
If .Value = .Offset(0, 2).Value Then
If .Value = .Offset(0, 3).Value Then
rCell.EntireRow.Delete
Else
End If
End If
End With
Next rCell
End With

The dupes arent deleted and I know I have to delete from the bottom
up€¦but
I dont think my code is doing that now. How can I change this to work
correctly?

Thanks,
Ryan---


--
RyGuy




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Delete if Three Matches in Three Columns

My data was a little screwed up before; didn't notice it. You were right and
I was wrong. Thanks so much!! Very helpful!!

Regards,
Ryan---

--
RyGuy


"Don Guillett" wrote:

Worked for me, AS TESTED, except for the email word wrap on the THEN. Excel
wants it this way
If Cells(i, "e") = Cells(i, "d") And Cells(i, "f") = Cells(i, "d") Then
or
If Cells(i, 6 = Cells(i, 4 )and Cells(i, 7) = Cells(i, 4) Then

Don Guillett
Microsoft MVP Excel
SalesAid Software

"ryguy7272" wrote in message
...
Well, thanks Don! That looks pretty sexy, but it didn't work as it was.
I
made a few minor changes, and still no luck. Working with this now:

For i = Cells(Rows.Count, 4).End(xlUp).Row To 2 Step -1
If Cells(i, 6) And Cells(i, 7) = Cells(i, 4) Then
Rows(i).Delete
End If
Next i

I get a Run-time Error 13; type mismatch.
Any ideas?

Thanks,
Ryan---

--
RyGuy


"Don Guillett" wrote:

try this
Sub deleltedupcolumns()
For i = Cells(Rows.Count, "d").End(xlUp).Row To 2 Step -1
If Cells(i, "e") = Cells(i, "d") And Cells(i, "f") = Cells(i, "d") Then
Rows(i).Delete
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"ryguy7272" wrote in message
...
I am trying to loop through a data set (sorted by ColumnD, ColumnF, and
ColumnG), and trying to delete dupes in ColumnD, ColumnF, and ColumnG.


'Compare and delete if dupes
Dim rCell As Range
With ActiveSheet
For Each rCell In .Range("D1:D" & _
.Range("D" & .Rows.Count).End(xlUp).Row)
With rCell
If .Value = .Offset(0, 2).Value Then
If .Value = .Offset(0, 3).Value Then
rCell.EntireRow.Delete
Else
End If
End If
End With
Next rCell
End With

The dupes arent deleted and I know I have to delete from the bottom
up€¦but
I dont think my code is doing that now. How can I change this to work
correctly?

Thanks,
Ryan---


--
RyGuy




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
Finding matches in two columns Erik Excel Worksheet Functions 4 April 26th 10 03:32 AM
Search for matches in two columns Dingy101 Excel Worksheet Functions 11 December 10th 09 05:58 AM
Delete rows if value matches Rob Excel Programming 5 March 13th 08 11:49 AM
How can I delete all matches in a workbook? LiveUser Excel Worksheet Functions 4 January 18th 08 08:55 PM
Calling all MVPs! Macro to delete non matches b/t two lists. Thank Excel User Excel Programming 2 March 19th 06 02:25 PM


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

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"