excel - Sheet to sheet multiple cell comparison -


i'm trying create code compare first column (dates) on sheet8 first column (dates) on sheet7. in addition, have compare 2nd columns on each sheet (shift). once program hits correct shift , date, need copy , paste data located on sheet7 sheet8. i've searched quite bit on , can't seem find correct answer. (note: new vba , self taught forgive me mistakes in code).

enter code here option explicit sub grabkpi() dim integer, j integer dim date1 date, date2 date dim shift1 integer, shift2 integer date1 = sheets("sheet8").range("a" & i) date2 = sheets("sheet7").range("a" & j) shift1 = sheets("sheet8").range("b" & i) shift2 = sheets("sheet7").range("b" & j)  = 2 1697 if date1 = date2     if shift1 = shift2         sheets("sheet7").activate         range("c" & j, "f" & j).select         selection.copy         sheets("sheet8").activate         range("i" & i).pastespecial xlpasteall         j = j + 1     else: j = j + 1     end if else: j = j + 1 end if = + 1 next end sub 

right now, error "application-defined or object-defined error" referring date1 , date2 statements. tried using general code different set , run nothing happen.

the reason why error you're trying access range doesn't exist. basically:

dim integer, j integer 

will declare i , j integer , assign them default value of 0. lines after, do:

date1 = sheets("sheet8").range("a" & i) date2 = sheets("sheet7").range("a" & j) 

being i , j equal 0, you're trying access range("a0") of 2 sheets. object doesn't exist, application-defined or object-defined error. if values in ranges range("a1") of 2 sheets, consider assigning correctly 2 values of i = 1 , j=1 before running date1 , date2 statements. solve 1004 error. effectiveness of rest of code, need debug basing on own data figure out coding inconsistency lies.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -