ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Delete row if double (https://www.excelbanter.com/excel-discussion-misc-queries/103326-delete-row-if-double.html)

bahri

Delete row if double
 
Hi all!
I have a sheet with 10 columns, and data is pasted (added) to it daily.
Sometimes there are duplicates, which I want to delete.
I am trying to write a macro that checks if A1 and B1 of the pasted row
already exist (after pasting), and if so delete the whole row.

Another macro I need is a pasting macro for these rows that pastes at the
bottom first empty row that exists.

Thanks for all the info here

bahri



Otto Moehrbach

Delete row if double
 
To find the first empty cell in Column A, call it Dest, use something like
this:
Set Dest = Range("A" & Rows.Count).End(xlUp).Offset(1))
To find out if the last entries in Column A & B are duplicates of something
above that row, and to delete that row is so, use something line this:
Sub DeleteDup()
Dim RngColA As Range
Dim LastA As Range
Dim LastB As Range
Set LastA = Range("A" & Rows.Count).End(xlUp)
Set LastB = LastA.Offset(, 1)
Set RngColA = Range("A1", LastA.Offset(-1))
If Not RngColA.Find(What:=LastA.Value, LookAt:=xlWhole) Is Nothing Then
_
If RngColA.Find(What:=LastA.Value, _
LookAt:=xlWhole).Offset(, 1).Value = _
LastB.Value Then LastA.EntireRow.Delete
End Sub
HTH Otto
"bahri" wrote in message
...
Hi all!
I have a sheet with 10 columns, and data is pasted (added) to it daily.
Sometimes there are duplicates, which I want to delete.
I am trying to write a macro that checks if A1 and B1 of the pasted row
already exist (after pasting), and if so delete the whole row.

Another macro I need is a pasting macro for these rows that pastes at the
bottom first empty row that exists.

Thanks for all the info here

bahri




bahri

Delete row if double
 
Hi!
Thanks a lot, will try things out.

bahri


"Otto Moehrbach" wrote in message
...
To find the first empty cell in Column A, call it Dest, use something like
this:
Set Dest = Range("A" & Rows.Count).End(xlUp).Offset(1))
To find out if the last entries in Column A & B are duplicates of
something above that row, and to delete that row is so, use something line
this:
Sub DeleteDup()
Dim RngColA As Range
Dim LastA As Range
Dim LastB As Range
Set LastA = Range("A" & Rows.Count).End(xlUp)
Set LastB = LastA.Offset(, 1)
Set RngColA = Range("A1", LastA.Offset(-1))
If Not RngColA.Find(What:=LastA.Value, LookAt:=xlWhole) Is Nothing Then
_
If RngColA.Find(What:=LastA.Value, _
LookAt:=xlWhole).Offset(, 1).Value = _
LastB.Value Then LastA.EntireRow.Delete
End Sub
HTH Otto
"bahri" wrote in message
...
Hi all!
I have a sheet with 10 columns, and data is pasted (added) to it daily.
Sometimes there are duplicates, which I want to delete.
I am trying to write a macro that checks if A1 and B1 of the pasted row
already exist (after pasting), and if so delete the whole row.

Another macro I need is a pasting macro for these rows that pastes at the
bottom first empty row that exists.

Thanks for all the info here

bahri







All times are GMT +1. The time now is 02:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com