vba - DLL "'-t" gives Run-time error 424: Object Required -


i using simple timer tells me time elapsed between performing same calculation different data types. when run error:

run-time error '424':

object required

the troublesome line:

target_sheet.range("a2").value = -t 

here of code:

public declare function gettickcount lib "kernel32.dll" () long sub function1_var_randnumcounter()  dim var_randnum_x, var_randnum_y, count variant  count = 1 count = 1000000     var_randnum_x = rnd(now) ' rnd vals based on now, built-in vba property     var_randnum_y = rnd(now) next count  target_sheet.range("a2").value = -t  '   msgbox gettickcount - t, , "milliseconds" call function1_dec_randnumcounter  end sub sub function1_dec_randnumcounter()  dim count, var_randnum_x, dec_randnum_x, var_randnum_y, dec_randnum_y  dec_randnum_x = cdec(var_randnum_x) dec_randnum_y = cdec(var_randnum_y) ' convert these vals decimals  count = 1 count = 1000000     dec_randnum_x = rnd(now) ' rnd vals based on now, built-in vba property     dec_randnum_y = rnd(now) next count  target_sheet.range("b2").value = -t  '   msgbox gettickcount - t, , "milliseconds" call function1_int_randnumcounter  end sub sub function1_int_randnumcounter()  dim count, int_randnum_x, int_randnum_y  count = 1 count = 1000000     int_randnum_x = rnd(now)     int_randnum_y = rnd(now) next count  target_sheet.range("c2").value = -t  '   msgbox gettickcount - t, , "milliseconds"  call function1_double_randnumcounter  end sub sub function1_double_randnumcounter()  dim count, dbl_randnum_x, dbl_randnum_y  count = 1 count = 1000000     dbl_randnum_x = rnd(now)     int_randnum_y = rnd(now) next count  target_sheet.range("d2").value = -t  '   msgbox gettickcount - t, , "milliseconds"  end sub sub function2_bargraph() '   put of these vals in 2d bar graph end sub 

the reason haven't assigned variable target_sheet, empty , when empty cannot call methods (i.e. range) since causes 'run-time error 424 - object required'.

you need assign worksheet variable target_sheet before use first time, i.e.:

set target_sheet = activesheet target_sheet.range("a2").value = -t 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -