VBA: Nested For/Loop -
i creating macro copy data 1 workbook/multiple sheets workbook/multiple sheets. first spreadsheet has 7 worksheets named sun-sat. second worksheet has 10 worksheets 3 worksheets irrelevant , other 7 worksheets named sunday-saturday.
i tested each loop separately , work needed. when trying combine them inner statement repeats , cycles through dates before backing out. have tried incorporating exit jump out of inner when going inner not increment +1 go next date. there simple way add +1 outer statement?
enter code here dim wsshortdays, wsfulldays variant dim wsshortdayscrnt, wsfulldayscrnt long dim sd, fd long wsshortdays = array("sun", "mon", "tue", "wed", "thu", "fri", "sat") wsfulldays = array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday") fd = lbound(wsfulldays) ubound(wsfulldays) wbk1.worksheets(wsfulldays(fd)) sd = lbound(wsshortdays) ubound(wsshortdays) wbk2.worksheets(wsshortdays(sd)) wbk2.worksheets(wsshortdays(sd)).activate range("a:h").copy end exit next sd wbk1.worksheets(wsfulldays(fd)).activate range("c:j").pastespecial xlpasteallusingsourcetheme sd = 1 end next fd
you not need inner loop arrays synced use same reference number first loop. equate sunday
sun
, forth:
dim wsshortdays variant, wsfulldays variant dim fd long wsshortdays = array("sun", "mon", "tue", "wed", "thu", "fri", "sat") wsfulldays = array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday") fd = lbound(wsfulldays) ubound(wsfulldays) wbk2.worksheets(wsshortdays(fd)).range("a:h").copy wbk1.worksheets(wsfulldays(fd)).range("c:j").pastespecial xlpasteallusingsourcetheme next fd
Comments
Post a Comment