Excel vba script: find() returns nothing on 2nd iteration -


for active_row = 9 last_row      ws1_func_loc = thisworkbook.sheets(ws1).cells(active_row, "c").value     ws1_mat_id = thisworkbook.sheets(ws1).cells(active_row, "d").value     ws1_mat_qty = thisworkbook.sheets(ws1).cells(active_row, "i").value     ws1_reason2 = ""       zc_sum = worksheetfunction.sumifs(thisworkbook.sheets(ws2).range("f:f"), thisworkbook.sheets(ws2).range("k:k"), ws1_func_loc, thisworkbook.sheets(ws2).range("n:n"), ws1_mat_id, thisworkbook.sheets(ws2).range("s:s"), "zc")     zk_sum = worksheetfunction.sumifs(thisworkbook.sheets(ws2).range("f:f"), thisworkbook.sheets(ws2).range("k:k"), ws1_func_loc, thisworkbook.sheets(ws2).range("n:n"), ws1_mat_id, thisworkbook.sheets(ws2).range("s:s"), "zk")       'some other if conditions...       elseif zc_sum = 0 , zk_sum > 0          row_match_count = worksheetfunction.countif(thisworkbook.sheets(ws2).range("k:k"), ws1_func_loc)          set found = thisworkbook.sheets(ws2).range("k:k").find(what:=ws1_func_loc) 'find() found nothing on 2nd iteration          = 1 row_match_count              if thisworkbook.sheets(ws2).cells(found.row, "n").value = ws1_mat_id , thisworkbook.sheets(ws2).cells(found.row, "s") = "zk" , not found nothing                   ws1_reason2 = ws1_reason2 & chr(10) & thisworkbook.sheets(ws2).cells(found.row, "r").value & ", " & "qty " & thisworkbook.sheets(ws2).cells(found.row, "f").value & ", " & thisworkbook.sheets(ws2).cells(found.row, "u").value & ", " & thisworkbook.sheets(ws2).cells(found.row, "w").value                   set found = sheets(ws2).range("k:k").findnext(after:=found)          else                  set found = sheets(ws2).range("k:k").findnext(after:=found)          end if      next      thisworkbook.sheets(ws1).cells(active_row, "o").value = ws1_reason2       elseif ....... 

i trying multi criteria search whereby finding rows in worksheet 2 (ws2) matches values in specific row in worksheet 1 (ws2).

it works during first for loop iteration, i.e. active_row = 9, during second iteration, i.e. when active_row = 10, set found = thisworkbook.sheets(ws2).range("k:k").find(what:=ws1_func_loc) returns nothing.

but there @ least match because row_match_count comes value greater 0.

i figured out what's wrong.

there bunch of drop down list in ws2 filter results.

if used drop down list filter rows, thisworkbook.sheets(ws2).range("k:k").find(what:=ws1_func_loc) able see/find filtered results, while worksheetfunction.countif(thisworkbook.sheets(ws2).range("k:k"), ws1_func_loc) still able see whole worksheet.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -