used range after clearing cells

B

BigRog

Help,
I am writing a new row to an existing sheet (vba Excel 2002), but don't want
any duplicate values in column "B". I was directed to an awsome sight with
the exact procedure that I needed. It is as follows (shortened ver):
'********
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lngRowCount = ActiveSheet.UsedRange.Rows
Col = ActiveCell.Column
If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
N = 0
For r = Rng.Rows.Count To 1 Step -1
V = Rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(Rng.Columns(1), V) > 1 Then
Rng.Rows(r).EntireRow.Delete
N = N + 1
End If
Next r
'*******like that

This worked fine until I decided that before finding the last unsed row I
should clear out any extra stuff in cells that may have something in them.
After using this procedure to clear any junk I always get " .UsedRange.Rows
= 65,xxx." in the previous procedure. The procedures have been shortened to
include what I consider the pertinent stuff.
'*************
lngVeryLastRow =
Workbooks(strCurrWb).Worksheets(strCurrSheet).UsedRange.Row - 1 + _

Workbooks(strCurrWb).Worksheets(strCurrSheet).Rows.Count
Application.ScreenUpdating = False
For r = intVeryLastRow To (intLastrow + 1) Step -1
Rows(r).ClearContents
If Application.CountA(Rows(r)) = 0 Then
Rows(r).ClearContents
Next r
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top