text - 2 different Ranges Compare from different Sheets not Working VBA -
why isnt text compare working? i'm trying compare 2 different ranges different sheets.
is there simple way of doing this?
sub selecttest() text3 = sheets("input data").range(cells(2, 2), cells(2, columns.count).end(xltoleft)) text4 = sheets("sap output data").range(cells(3, 1), cells(rows.count, 1).end(xlup)) if strcomp(text3, text4, vbtextcompare) = 0 else cells(cell.row, "a").interior.colorindex = 26 cells(cell.row, "b").interior.colorindex = 26 cells(cell.row, "c").interior.colorindex = 26 cells(cell.row, "d").interior.colorindex = 26 end if end sub
is there im doing incorrectly?
also tried no errors wont solve:
sub comprangetest() thisworkbook.sheets("input data") text3 = range(cells(2, 2), cells(2, columns.count).end(xltoleft)).select end thisworkbook.sheets("sap output data") text4 = sheets("sap output data").range(cells(3, 1), cells(rows.count, 1).end(xlup)).select end 'text3 = sheets("input data").range(cells(2, 2), cells(2, columns.count).end(xltoleft)) 'text4 = sheets("sap output data").range(cells(3, 1), cells(rows.count, 1).end(xlup)) if strcomp(text3, text4, vbtextcompare) = 0 else activesheet.cells(cell.row, "a").interior.colorindex = 26 activesheet.cells(cell.row, "b").interior.colorindex = 26 activesheet.cells(cell.row, "c").interior.colorindex = 26 activesheet.cells(cell.row, "d").interior.colorindex = 26 end if end sub
am using correct method?
instead of comparing different sheets, brought range on current sheet , made requirement use selection before compare initiates. since source range on row, used k integer source is. source changes , above selection. line used compare. of coarse can go further , create selection range sheet. works me now. hope saved time other people struggling was.
sub compareranges() application.screenupdating = false dim report worksheet dim integer, j integer, k integer dim lastrow integer dim lastcolumn integer dim sht worksheet dim cell range dim x long, y long set sht = thisworkbook.sheets("sap output data") lastrow = sht.usedrange.rows.count lastcolumn = sht.usedrange.columns.count 'if selection nothing 'msgbox "nothing selected, please select range." 'else 'x first row number of selection, y last. x = selection.rows(1).row y = selection.rows.count + x - 1 'msgbox x & " " & y 'give row number of cell above selection. k = selection.rows(1).offset(-1, 0).row 'msgbox k = x y 'lastrow 'for = 3 lastrow 'lastrow j = 5 lastcolumn if sht.cells(i, 1).value <> "" 'this omit blank cells @ end (in event column lengths not equal. 'sht.cell (2, j) "k variable source." if instr(1, sht.cells(k, j).value, sht.cells(i, 1).value, vbtextcompare) > 0 sht.cells(i, 1).interior.color = rgb(255, 255, 255) 'white background sht.cells(i, 1).font.color = rgb(0, 0, 0) 'black font color exit else sht.cells(i, 1).interior.color = rgb(156, 0, 6) 'dark red background sht.cells(i, 1).font.color = rgb(255, 199, 206) 'light red font color end if end if next j next 'end if application.screenupdating = true end sub
Comments
Post a Comment