View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Very small macro/VBA stuff, deleting rows.

j = ActiveSheet.UsedRange.Rows.Count + ActiveSheet.UsedRange.Row - 1

will either be equivalent to

cells(.Rows.Count,7).End(xlup).row

or it will start at a higher row number and delete rows between that row and
the first cell with a value in column 7. (since a blank cell will match a
blank cell)

What you use will depend on what you want to accomplish.

--
Regards,
Tom Ogilvy


"Sintel " wrote in message
...
I have taken the three of your replies in account and this is what I
ended up with.


Code:
--------------------

Sub DeleteDoubles()
Worksheets("sheet1").Activate
Dim i As Integer, j As Integer
j = ActiveSheet.UsedRange.Rows.Count + ActiveSheet.UsedRange.Row - 1
For i = j To 1 Step -1
If ActiveSheet.Cells(i, 7).Value = ActiveSheet.Cells(i - 1, 7).Value

Then
Rows(i).Delete Shift:=xlUp
End If
Next i
End Sub

--------------------


I used the last row expression from Roderick, the backwards structure
from Jarek, but it still wouldn't compile, then I saw Tom's reply and
changed the 1 into a 2 and it worked! I checked your algorithm too tom
and it works as well. I could probably do this without the two integers
but i'm not too concerned with efficiency right now ^^ thx a bunch all.


---
Message posted from http://www.ExcelForum.com/