ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro needed to delete rows (https://www.excelbanter.com/excel-programming/357241-macro-needed-delete-rows.html)

simmerdown

Macro needed to delete rows
 
I have a list of numbers that I want to narrow down to unique numbers....in
other words, I want to delete the row if a number show is already displayed
elsewhere.

Example list:

1
2
2
2
3
4
4
4

I am searching for a macro that will delete the rows containing the extras
"2's" and "4's".

Tom Ogilvy

Macro needed to delete rows
 
Sub DeleteDups()
Dim lastrow as Long, i as Long
Dim rng as Range
With Worksheets("Sheet1")
lastrow = .Cells(rows.count,"A").End(xlup).Row
for i = lastrow to 2 step - 1
set rng = .Range(.cells(1,"A"),.Cells(i-1,"A"))
if application.Countif(rng,.cells(i,"A").Value)0 then
rows(i).Delete
end if
Next
End With
End Sub

--
Regards,
Tom Ogilvy


"simmerdown" wrote:

I have a list of numbers that I want to narrow down to unique numbers....in
other words, I want to delete the row if a number show is already displayed
elsewhere.

Example list:

1
2
2
2
3
4
4
4

I am searching for a macro that will delete the rows containing the extras
"2's" and "4's".


Chip Pearson

Macro needed to delete rows
 
Try the following

Sub AAA()
Dim LastRow As Long
Dim RowNdx As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 2 Step -1
If Cells(RowNdx, "A") = Cells(RowNdx - 1, "A") Then
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub

This assumes your data is in column A and starts in row 1.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"simmerdown" wrote in
message
...
I have a list of numbers that I want to narrow down to unique
numbers....in
other words, I want to delete the row if a number show is
already displayed
elsewhere.

Example list:

1
2
2
2
3
4
4
4

I am searching for a macro that will delete the rows containing
the extras
"2's" and "4's".




Don Guillett

Macro needed to delete rows
 
One easy way is to use datafilteradvanced filterunique itemscopy
elsewhere. Record a macro if desired.

--
Don Guillett
SalesAid Software

"simmerdown" wrote in message
...
I have a list of numbers that I want to narrow down to unique numbers....in
other words, I want to delete the row if a number show is already
displayed
elsewhere.

Example list:

1
2
2
2
3
4
4
4

I am searching for a macro that will delete the rows containing the extras
"2's" and "4's".




simmerdown

Macro needed to delete rows
 
Thank you very much, Tom

"simmerdown" wrote:

I have a list of numbers that I want to narrow down to unique numbers....in
other words, I want to delete the row if a number show is already displayed
elsewhere.

Example list:

1
2
2
2
3
4
4
4

I am searching for a macro that will delete the rows containing the extras
"2's" and "4's".



All times are GMT +1. The time now is 04:18 PM.

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