search - VBA:program optimization -


so question 2 parts. first seeing whether there quick , simple code can incorporate current sub check how fast sub take run. need precision down seconds, , maybe couple of minutes.

the 2nd trying optimize run time of sub. search function allows user specify variables select search , displays results on following worksheet. i've surfed net , i've done following general applications speed program

  1. disable screen updating @ beginning of sub
  2. avoid copy&paste clipboard as possible

however, program still takes ~5 10 seconds run everytime user runs search. decrease time as possible.

i realize without looking @ code hard give specific suggestions, looking general suggestions. if still slow after general principles have been implemented post code here.

my search program linear search program , stores values array. search function can accomodate 4 search variables though , store each search array , consolidate array @ end final results array.

i use gettickcount api function. long you're not intending measure time on weeks or months should accurate. below example shows different looping measures being timed. 1 tick = 1ms

private declare function gettickcount lib "kernel32" () long   sub test()  dim ntime   ntime = gettickcount  set load_array = range("a5:z65000")  array_index = worksheetfunction.match("test 15", worksheetfunction.index(load_array, 0, 1), 0)   rngtimer = gettickcount - ntime    ntime = gettickcount  load_array = range("a5:z65000").value  array_index = worksheetfunction.match("test 15", worksheetfunction.index(load_array, 0, 1), 0)   arraytimer = gettickcount - ntime    ntime = gettickcount  load_array = range("a5:z65000").value  = lbound(load_array) ubound(load_array)  if load_array(a, 1) = "test 15"  array_index =  end if  next   arraylooptimer = gettickcount - ntime   ntime = gettickcount   = 1 65000  if range("a5").offset(a, 0) = "test 15"  array_index =  end if  next   excelooptimer = gettickcount - ntime   msgbox ("range search: " & rngtimer & vbcrlf & _  "array search: " & arraytimer & vbcrlf & _  "arrayloop search: " & arraylooptimer & vbcrlf & _  "excelloop search: " & excelooptimer)  end sub  

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -