excel - mismatch error for sheetname -
i wondering why keep facing mismatch error
if (sheets(newsheetname).rows(l).cells(1, 2).value = product) then
the code trying figure out , match cells , loop across different worksheets.
see below code :
dim range1, range2 range 'define variables dim referencesheetcols integer dim range1rows, range1cols, range2rows, range2cols, testrows, testcols, i, j, p long dim bmatches, rowmatched boolean dim product string product = "producta" newsheetcols = 2123 referencesheetcols = 2123 ' how many rows , columns should compare? testrows = 1 testcols = 7 p = sheets(referencesheetname).usedrange.rows.count l = 7 newsheetcols 'only test if correct product **if (sheets(newsheetname).rows(l).cells(1, 2).value = product) then** rowmatched = false k = 7 referencesheetcols 'bmatch = false set range1 = sheets(referencesheetname).rows(k) set range2 = sheets(newsheetname).rows(l) ' count rows , columns in each of ranges range1rows = range1.rows.count range1cols = range1.columns.count range2rows = range2.rows.count range2cols = range2.columns.count 'are ranges same dimension? bmatches = (range1rows = range2rows , range1cols = range2cols) 'if same dimensions loop through cells if bmatches = 1 testrows j = 1 testcols if (range1.cells(i, j).value <> range2.cells(i, j).value) bmatches = false = testrows j = testcols end if next next end if if bmatches rowmatched = true k = referencesheetcols end if 'sheets(outputsheetname).cells(1, 1).value = rowmatched if (not (rowmatched) , k = referencesheetcols) range2.copy sheets(outputsheetname).range("a1:a6000").cells(p, 1).offset(2, 0).select activesheet.paste p = p + 1 end if next end if next end sub
to complete question inline guidelines,
if cstr(sheets(newsheetname).rows(l).cells(1, 2).value) = product rowmatched = false k = 7 referencesheetcols
Comments
Post a Comment