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.

https://support.office.com/en-us/article/use-a-formula-to-apply-conditional-formatting-in-excel-2013-fed60dfa-1d3f-4e13-9ecb-f1951ff89d7f?ui=en-us&rs=en-za&ad=za


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -