PC Review


Reply
Thread Tools Rate Thread

Delete row/s with the same elements as the above row

 
 
Arno
Guest
Posts: n/a
 
      25th Nov 2008
Hello,

Is there a way to delete row/s that contain all cells with the same
text/element as the row above ?

I tried this syntax but I get run time error 13 - type mismatch

If c.Value <> c.Offset(-1, 0).Value Then FOR THIS LINE I GET THE DEBUGGER


Sub delMatchedRows()
Dim lr As Long, x As Long
Dim c As Range
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 2 Step -1
For Each c In Rows(i).Cells
If c.Value <> c.Offset(-1, 0).Value Then HERE I GET THE DEBUGGER
x = x + 1
End If
Next
If x = 0 Then
Rows(i).Delete
End If
x = 0
Next
End Sub

Thank you !!
 
Reply With Quote
 
 
 
 
RadarEye
Guest
Posts: n/a
 
      25th Nov 2008
Hi Arno

Try this, created with Excel 2003:

Sub RemoveRepeatedRow()
Dim blnRemove As Boolean
Dim intCols As Integer
Dim intCol As Integer

ActiveSheet.UsedRange.Cells(2, 1).Select
intCols = ActiveSheet.UsedRange.Columns.Count - 1
Do
blnRemove = True
For intCol = 0 To intCols
If ActiveCell.Offset(0, intCol).Value <> ActiveCell.Offset
(-1, intCol).Value Then
blnRemove = False
Exit For
End If
Next
If blnRemove Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell)

End Sub


HTH,

Wouter
 
Reply With Quote
 
Arno
Guest
Posts: n/a
 
      25th Nov 2008
Hi Wouter,

this line is in error bocomes red

If ActiveCell.Offset(0, intCol).Value <> ActiveCell.Offset
(-1, intCol).Value Then

can you please check thanks !

"RadarEye" wrote:

> Hi Arno
>
> Try this, created with Excel 2003:
>
> Sub RemoveRepeatedRow()
> Dim blnRemove As Boolean
> Dim intCols As Integer
> Dim intCol As Integer
>
> ActiveSheet.UsedRange.Cells(2, 1).Select
> intCols = ActiveSheet.UsedRange.Columns.Count - 1
> Do
> blnRemove = True
> For intCol = 0 To intCols
> If ActiveCell.Offset(0, intCol).Value <> ActiveCell.Offset
> (-1, intCol).Value Then
> blnRemove = False
> Exit For
> End If
> Next
> If blnRemove Then
> ActiveCell.EntireRow.Delete
> Else
> ActiveCell.Offset(1, 0).Select
> End If
> Loop Until IsEmpty(ActiveCell)
>
> End Sub
>
>
> HTH,
>
> Wouter
>

 
Reply With Quote
 
RadarEye
Guest
Posts: n/a
 
      25th Nov 2008
Hi Arno

This is one line of code.

If you change it to

If ActiveCell.Offset(0, intCol).Value <> _
ActiveCell.Offset(-1, intCol).Value Then

it must work.

It works fine for me.

Wouter
 
Reply With Quote
 
Arno
Guest
Posts: n/a
 
      25th Nov 2008
Thank you for coming back !

"RadarEye" wrote:

> Hi Arno
>
> This is one line of code.
>
> If you change it to
>
> If ActiveCell.Offset(0, intCol).Value <> _
> ActiveCell.Offset(-1, intCol).Value Then
>
> it must work.
>
> It works fine for me.
>
> Wouter
>

 
Reply With Quote
 
Arno
Guest
Posts: n/a
 
      25th Nov 2008
It works great - Many thanks - Appreciated !

"Arno" wrote:

> Thank you for coming back !
>
> "RadarEye" wrote:
>
> > Hi Arno
> >
> > This is one line of code.
> >
> > If you change it to
> >
> > If ActiveCell.Offset(0, intCol).Value <> _
> > ActiveCell.Offset(-1, intCol).Value Then
> >
> > it must work.
> >
> > It works fine for me.
> >
> > Wouter
> >

 
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 row with the same elements as the one above Arno Microsoft Excel Programming 3 24th Nov 2008 05:40 PM
Can't delete elements in folder Recent elements Gudmund Liebach Nielsen Windows Vista General Discussion 0 16th Oct 2007 04:06 PM
Delete List elements shapper Microsoft ASP .NET 0 10th Oct 2007 02:25 AM
Delete elements in .NET collections headware Microsoft Dot NET Framework 3 12th Aug 2005 05:14 PM
How to search and delete elements from a XML file? richardkreidl@northwesternmutual.com Microsoft VB .NET 2 18th Apr 2005 04:58 PM


Features
 

Advertising
 

Newsgroups
 


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