Last row two times.

soidog

New Member
Joined
May 26, 2016
Messages
45
Hello,
This code works but:
After removing duplicates in column "A", I get a new last row in column "A" so I must "declaire" "lrow" again so dates in column "B" are not filled in to the first "lrow".
Is there a way around this?

Code:
Sub Start()


Dim ws As Worksheet
Dim lrow As Long


Set ws = ActiveSheet


[COLOR=#ff0000]lrow = ActiveSheet.Range("A" & Rows.count).End(xlUp).Row[/COLOR]
Application.ScreenUpdating = False


    ws.Range("B7", ws.Cells(lrow, "U")).ClearContents
    ws.Range("A7", ws.Cells(lrow, "A")).RemoveDuplicates Columns:=1, Header:=xlNo
       
[COLOR=#ff0000]lrow = ActiveSheet.Range("A" & Rows.count).End(xlUp).Row[/COLOR]
    ws.Range("B7", ws.Cells(lrow, "B")) = Date
    
Application.ScreenUpdating = True
    
End Sub

Thanks in advance. :)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Do you really need to find the initial last row at all?
You can probably apply the Remove Duplicates functionality to the whole column (blank rows shouldn't affect it), i.e.
Code:
Range("A:A").RemoveDuplicates Columns:=1, Header:=xlNo
You can then calculate the lrow variable after removing the duplicates.
 
Upvote 0
Hi Joe,
Thanks for your answer but that will not work. I have "stuff" above row 6 that must be there.
Row 6 have headers for columns "A:U" so data starts at row 7.
 
Upvote 0
You could still do it, using Rows.Count, i.e.
Code:
    ws.Range("A7", ws.Cells(Rows.Count, "A")).RemoveDuplicates Columns:=1, Header:=xlNo
 
Upvote 0

Forum statistics

Threads
1,216,558
Messages
6,131,400
Members
449,648
Latest member
kyouryo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top