Excel VBA : Not responding Or Ultra long runtime with DoEvents -
hi , reading !
i've looked answers problem didn't found enough...
here idea of code : in table there number of column (chambre) , number of row (alveole). if these matches in list in other sheet checks if date between 2 dates on second sheets. if matches 3 things, puts sheet
my code works if add "doevents" in every for, else excel , vba stops responding. takes aroung 5 minutes , need to 4 tables...
is code not efficient ? have ideas how make better ? advices appreciated !
here code
sub alveoles() application.screenupdating = true dim moment date 'variables photo dim 4 integer dim chambre integer dim alveole integer dim aaa integer dim ccc integer 'variables gems dim ligne integer dim enfournement date dim defournement date dim lastrow integer 'set date , lastrow moment = worksheets("photo").range("o2").value lastrow = worksheets("gems").range("a" & rows.count).end(xlup).row 4 = 1 'four1 1 row ligne = 2 lastrow doevents chambre = 1 38 doevents alveole = 1 6 doevents enfournement = worksheets("gems").range("d" & ligne).value defournement = worksheets("gems").range("e" & ligne).value if 4 = worksheets("gems").range("a" & ligne).value , _ chambre = worksheets("gems").range("b" & ligne).value , _ alveole = worksheets("gems").range("c" & ligne).value , _ moment > enfournement , _ moment < defournement aaa = alveole + 5 ccc = chambre + 2 worksheets("photo").cells(aaa, ccc).interior.colorindex = 1 'noir end if next alveole next chambre next ligne end sub
assuming code end goal set format of cell under conditions, think vba unnecessary here , should consider using conditional formatting. built in excel, lightening fast , easier maintain.
if can make data excel tables (ribbon: format table), conditional formatting automatically copy down each new row add.
check out microsoft support article show how it's done.
Comments
Post a Comment