vba - Row Comparision in Excel -
i'm facing problem 1 of macros i've written compare rows in sheet , highlight duplicates if any. but, taking longer time complete it's operation when there more number of records. when comparision starts, picks first record, compares remaining records , highlight if there duplicate , moves on second record , process continues till last record.
can tell me better solution this?
here code;
rowcount = activesheet.usedrange.rows.count columncount = activesheet.usedrange.columns.count frownum = 1 rowcount rownum = 1 rowcount recfound = 0 colnum = 1 columncount if frownum <> rownum if activesheet.cells(frownum, colnum).value = activesheet.cells (rownum, colnum).value recfound = recfound + 1 end if end if next colnum if columncount = recfound errrow = 1 columncount thisworkbook.worksheets("rowcompare").cells(frownum, errrow).interior.color = rgb(251, 231, 128) next errrow end if next rownum next frownum
sub test2() dim rowcount long dim columncount long '//you need "microsoft scripting runtime" library work '//you can add library going tools -> references -> browse... '//find "scrrun.dll" file in system32 folder dim dict scripting.dictionary set dict = new scripting.dictionary dim ws worksheet set ws = activesheet ws rowcount = .usedrange.rows.count columncount = .usedrange.columns.count dim long = 1 rowcount dim rng range dim joinedrow string set rng = range(.cells(i, 1), .cells(i, columncount)) joinedrow = join(application.transpose(application.transpose(rng)), chr(0)) if dict.exists(joinedrow) rng.interior.color = rgb(251, 231, 128) else dict.add joinedrow, 1 end if next end end sub
improved ideas, used here: how compare 2 entire rows in sheet case, adding scripting.dictionary class.
hope works.
Comments
Post a Comment