excel - VBA - Remove duplicates from bottom -
i running loop add notes end of running list. having problem removing duplicates based on identifier in column 1. following code works if duplicates same in both columns.
sub note_update() dim ws worksheet dim notes_ws worksheet dim row dim lastrow dim notes_nextrow 'find worksheet called notes each ws in worksheets if ws.name = "notes" set notes_ws = ws end if next ws 'get nextrow print notes_nextrow = notes_ws.range("a" & rows.count).end(xlup).row + 1 'loop through other worksheets each ws in worksheets 'ignore notes worksheet if ws.name <> "notes" , ws.index > sheets("master").index 'find lastrow lastrow = ws.range("l" & rows.count).end(xlup).row row = 2 lastrow 'if cell not empty if ws.range("l" & row) <> "" notes_ws.range("b" & notes_nextrow).value = ws.range("l" & row).value notes_ws.range("a" & notes_nextrow).value = ws.range("f" & row).value notes_nextrow = notes_nextrow + 1 end if next row end if next ws notes_ws.range("a:b").removeduplicates columns:=array(1, 2), header:=xlyes end sub
if change last line of following code, remove duplicates based solely on identifier in first column.
notes_ws.range("a:b").removeduplicates columns:=array(1, 1), header:=xlyes
the problem removes duplicate bottom of list bottom recent note i'd keep.
question: how remove duplicates , leave bottom-most note based solely on column 1?
thanks help!
i added additional piece of code inserts column left , adds row number, tracks order of comments. sorted descending oldest comments go bottom of list. removed duplicates , re-sort list , remove number column.
here updated code follows loop:
columns("a:a").entirecolumn.insert = 1 notes_nextrow thisworkbook.activesheet.range("a" & i).formula = "=row()" next columns("a:a").copy columns("a:a").pastespecial (xlpastevalues) range("a:c").sort key1:=range("a:a"), order1:=xldescending, header:=xlyes notes_ws.range("a:c").removeduplicates columns:=2, header:=xlyes range("a:c").sort key1:=range("a:a"), order1:=xlascending, header:=xlyes columns("a:a").delete range("a1").select
Comments
Post a Comment