excel - Error Help: Adding to ranges using Application.Union -


i attempting loop through large list rows searching specific column values based on values in tab. had working 1 value add second criteria receiving errors on "set tworange = application.union(tworange, cell.entirerow)". have entered code below.

is aware of why might receiving these errors?

edit: error "run-time error '5': invalid procedure call or argument

sub calculate()  '----data pull----'   dim cell range   dim onerange range   dim tworange range   dim threerange range   dim fourrange range   dim fiverange range   dim sixrange range   dim sevenrange range   dim eightrange range   dim ninerange range   dim tenrange range    dim mycount long   dim existcount long   existcount = 0   mycount = 1     each cell in worksheets("data").range("c2:c99999")    if cell.value = worksheets("calculation").range("b8").value   existcount = existcount + 1       if mycount = 1 set onerange = cell.offset(0, -1)       set onerange = application.union(onerange, cell.entirerow)       mycount = mycount + 1     elseif cell.value = worksheets("calculation").range("b9").value       existcount = existcount + 1       if mycount = 1 set tworange = cell.offset(0, -1)       set tworange = application.union(tworange, cell.entirerow)       mycount = mycount + 1     end if   next cell     if existcount > 0     onerange.copy destination:=worksheets("lob one").range("a3")   end if    if existcount > 0     tworange.copy destination:=worksheets("lob two").range("a3")   end if  end sub 

answered tim williams in comments.

it's possible tworange still nothing when problem line runs. need separate "mycount" variables tracking onerange , tworange

thanks taking time help!


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -