VBA excel search multiple columns -



VBA excel search multiple columns -

i trying search through multiple columns particular value. code have below searching column d. whenever alter error. want search columns d m. thanks

do while (range("d" & cstr(lsearchrow)).value) > 0 'if value in column d = lsearchvalue, re-create entire row sheet2 if range("d" & cstr(lsearchrow)).value = lsearchvalue 'select row in sheet1 re-create rows(cstr(lsearchrow) & ":" & cstr(lsearchrow)).select selection.copy 'paste row sheet2 in next row sheets("sheet2").select rows(cstr(lcopytorow) & ":" & cstr(lcopytorow)).select activesheet.pastespecial 'move counter next row lcopytorow = lcopytorow + 1 'go sheet1 go on searching sheets("sheet1").select end if lsearchrow = lsearchrow + 1 loop

i redid code in next way, hope find helpful.

sub searchvalue() dim lsearchvalue string dim lsearchrow integer dim lcopytorow integer dim icolumn integer 'i'm looking string = "5", alter value or pass through procedure parameter lsearchvalue = "5" lcopytorow = 1 icolumn = 4 13 lsearchrow = 1 while sheets("sheet1").cells(lsearchrow, icolumn).value > 0 if sheets("sheet1").cells(lsearchrow, icolumn).value = lsearchvalue 'select row in sheet1 re-create rows(lsearchrow).select selection.copy 'paste row sheet2 in next row sheets("sheet2").select rows(lcopytorow).select activesheet.pastespecial 'move counter next row lcopytorow = lcopytorow + 1 'go sheet1 go on searching sheets("sheet1").select end if lsearchrow = lsearchrow + 1 wend next icolumn end sub

excel vba excel-vba

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -