excel vba - defining lots of different variables -


is there faster way define following variables. notact name, after name comes cells positions. "b" column , number refers row. value 0. single cell has defined can use variables.

dim notact_b1, notact_c1, notact_d1, ..., notact_d20 integer      notact_b1 = 0     notact_c1 = 0     notact_d1 = 0     notact_b2 = 0     notact_c2 = 0     notact_d2 = 0     notact_b3 = 0     notact_c3 = 0     notact_d3 = 0     notact_b4 = 0     notact_c4 = 0     notact_d4 = 0     notact_b5 = 0     notact_c5 = 0     notact_d5 = 0     notact_b6 = 0     notact_c6 = 0     notact_d6 = 0     notact_b7 = 0     notact_c7 = 0     notact_d7 = 0     notact_b8 = 0     notact_c8 = 0     notact_d8 = 0     notact_b9 = 0     notact_c9 = 0     notact_d9 = 0     notact_b10 = 0     notact_c10 = 0     notact_d10 = 0     notact_b11 = 0     notact_c11 = 0     notact_d11 = 0     notact_b12 = 0     notact_c12 = 0     notact_d12 = 0     notact_b13 = 0     notact_c13 = 0     notact_d13 = 0     notact_b14 = 0     notact_c14 = 0     notact_d14 = 0     notact_b15 = 0     notact_c15 = 0     notact_d15 = 0     notact_b16 = 0     notact_c16 = 0     notact_d16 = 0     notact_b17 = 0     notact_c17 = 0     notact_d17 = 0     notact_b18 = 0     notact_c18 = 0     notact_d18 = 0     notact_b19 = 0     notact_c19 = 0     notact_d19 = 0     notact_b20 = 0     notact_c20 = 0     notact_d20 = 0 

first of all, don't need initialize integer variable in vba - 0 after dimmed.

however, instead of defining 4x20 variables, better use array:

dim notact(1 20,1 43) integer 

if need initialize or reset values, can use small loop:

dim col integer, row long  'initialize/reset col = 1 4     row = 1 20         notact(row, col) = 0 'setting 0 not required after dim     next row next col 

if need assign value of variable cell, use syntax:

'assigns value array b3 cells(3, 2).value = notact(3, 2) 

and best of all, if want assign 4x20 cells values, use 1 line of code:

range("a1:d20").value = notact 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -