vba - Find duplicate data in sheet1 and if it is found in sheet2 then it has to highlight with some specific design(Color) -
sub compare2sheets() dim ws1 workbook, ws2 workbook dim s1 string, s2 string s1 = inputbox("enter 1st sheet name") s2 = inputbox("enter 2nd sheet name") set ws1 = sheets("s1") set ws2 = sheets("s2") dim rcount long, ccount long rcount = ws1.usedrange.rows.count ccount = ws1.usedrange.columns.count dim r long, c integer r = 1 rcount c = 1 ccount if ws1.cells(r, c) <> ws2.cells(r, c) ws2.cells(r, c).interior.colorindex = 6 end if next c next r set ws1 = nothing set ws2 = nothing end sub
question: not able execute above code. how execute code?
ws1 , ws2 declared workbooks, should declared worksheets. change first line of code to:
dim ws1 worksheet, ws2 worksheet
furthermore youe have remove double quotes when referring worksheets:
set ws1 = sheets(s1) set ws2 = sheets(s2)
Comments
Post a Comment