Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default Delete row problem, could some help me on that?

Hello guys,

I have a problem with this small sub, I would like to delete the row it
the value of one cell is egual of the value of cell + 1 but I have this
problem delete method of range class failed and I do not know why?

Sub deletequalrow()
Dim LastRow As Long
Dim i As Long


With ActiveSheet.UsedRange
LastRow = .Cells(.Cells.Count).Row
End With


For i = LastRow To 1 Step -1
If Cells(i, "B").Value = Cells(i - 1, "B").Value Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub

Ina

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Delete row problem, could some help me on that?

For one thing, when i = 1, there is no cell i-1, "B". Try
For i=LastRow to 2 step -1
James
ina wrote:
Hello guys,

I have a problem with this small sub, I would like to delete the row it
the value of one cell is egual of the value of cell + 1 but I have this
problem delete method of range class failed and I do not know why?

Sub deletequalrow()
Dim LastRow As Long
Dim i As Long


With ActiveSheet.UsedRange
LastRow = .Cells(.Cells.Count).Row
End With


For i = LastRow To 1 Step -1
If Cells(i, "B").Value = Cells(i - 1, "B").Value Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub

Ina


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default Delete row problem, could some help me on that?

The Cell procedu Cells(i, "B").Value is wrong, the first parameter is a
row index which you have, but the second is not a string it should be the
number 2 if you want to use column B

"ina" wrote:

Hello guys,

I have a problem with this small sub, I would like to delete the row it
the value of one cell is egual of the value of cell + 1 but I have this
problem delete method of range class failed and I do not know why?

Sub deletequalrow()
Dim LastRow As Long
Dim i As Long


With ActiveSheet.UsedRange
LastRow = .Cells(.Cells.Count).Row
End With


For i = LastRow To 1 Step -1
If Cells(i, "B").Value = Cells(i - 1, "B").Value Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub

Ina


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete row problem, could some help me on that?

I think you're confusing Range("B13") with cells(13,"B") or cells(13,2)

(I used row 13 just so there wouldn't be too many 2's.)

Michael wrote:

The Cell procedu Cells(i, "B").Value is wrong, the first parameter is a
row index which you have, but the second is not a string it should be the
number 2 if you want to use column B

"ina" wrote:

Hello guys,

I have a problem with this small sub, I would like to delete the row it
the value of one cell is egual of the value of cell + 1 but I have this
problem delete method of range class failed and I do not know why?

Sub deletequalrow()
Dim LastRow As Long
Dim i As Long


With ActiveSheet.UsedRange
LastRow = .Cells(.Cells.Count).Row
End With


For i = LastRow To 1 Step -1
If Cells(i, "B").Value = Cells(i - 1, "B").Value Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub

Ina



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default Delete row problem, could some help me on that?

Thanks a lot guys it works now.

Ina
Michael wrote:
The Cell procedu Cells(i, "B").Value is wrong, the first parameter is a
row index which you have, but the second is not a string it should be the
number 2 if you want to use column B

"ina" wrote:

Hello guys,

I have a problem with this small sub, I would like to delete the row it
the value of one cell is egual of the value of cell + 1 but I have this
problem delete method of range class failed and I do not know why?

Sub deletequalrow()
Dim LastRow As Long
Dim i As Long


With ActiveSheet.UsedRange
LastRow = .Cells(.Cells.Count).Row
End With


For i = LastRow To 1 Step -1
If Cells(i, "B").Value = Cells(i - 1, "B").Value Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub

Ina





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete row problem, could some help me on that?

You're going from the lastrow to 1 step -1

So the last thing you're doing is comparing

if cells(1,"B").value = cells(0,"B").value then
(1-1 is 0)

Try changing your loop to stop at row 2.

For i = LastRow To 2 Step -1



ina wrote:

Hello guys,

I have a problem with this small sub, I would like to delete the row it
the value of one cell is egual of the value of cell + 1 but I have this
problem delete method of range class failed and I do not know why?

Sub deletequalrow()
Dim LastRow As Long
Dim i As Long

With ActiveSheet.UsedRange
LastRow = .Cells(.Cells.Count).Row
End With

For i = LastRow To 1 Step -1
If Cells(i, "B").Value = Cells(i - 1, "B").Value Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub

Ina


--

Dave Peterson
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
Problem of selection.delete Radhakrishna k.v.n.r[_2_] Excel Worksheet Functions 7 October 27th 07 11:50 AM
Problem Using Delete Key Because of Combobox Joseph Fletcher Excel Discussion (Misc queries) 11 February 23rd 07 01:45 PM
Delete problem Loi New Users to Excel 3 December 8th 04 01:35 AM
Delete Sheets Problem Edgar Thoemmes[_4_] Excel Programming 3 October 27th 04 12:32 PM
Name Delete Problem Again Meme Excel Programming 1 April 9th 04 03:31 AM


All times are GMT +1. The time now is 04:09 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"