Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Delete row/s with the same elements as the above row

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 !!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Delete row/s with the same elements as the above row

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Delete row/s with the same elements as the above row

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Delete row/s with the same elements as the above row

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Delete row/s with the same elements as the above row

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Delete row/s with the same elements as the above row

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
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
question about SUM - how to sum each for elements [email protected] Excel Worksheet Functions 5 February 5th 09 09:57 AM
Delete row with the same elements as the one above Arno Excel Programming 3 November 24th 08 05:40 PM
elements in an array Alan Beban[_2_] Excel Programming 0 November 21st 07 08:21 PM
Protection elements Eva Excel Discussion (Misc queries) 2 February 16th 07 09:58 AM
conditionally delete some elements from an array clui[_8_] Excel Programming 1 December 4th 03 01:21 AM


All times are GMT +1. The time now is 09:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"