vba that search for a value if it matches find closest date -


i wrote code workbook have 2 worksheet´s, in proximopedido (sheet) in column "a" there range of values (integer number) , in colunm "b" there date associated, , in chekinglist (sheet) there colunm "a" values (wich must match "a" of proximopedido) , colunm "e" dates. if value of cell of checkinglist matches value of "a" of proximopedido search in "e" of chekinglist next ( or closest higher) date of "b" proximopedido.

sheet: checkinglist

a-----------------------------------------e

1----------------------------------2009-10-30 12:00

3 ---------------------------------2009-10-29 13:00

2---------------------------------2009-10-29 12:20

50--------------------------------2009-10-19 10:20

24--------------------------------2009-10-28 10:20

3----------------------------------2009-10-28 10:20 <-------- ( match!)

sheet: proximo pedido

a----------------------------------------b

4----------------------------------2009-10-28 10:20

20---------------------------------2009-10-29 13:00

3----------------------------------2009-10-19 15:20

24---------------------------------2009-10-29 13:40

3-----------------------------------2009-10-27 13:20 <------------ (example)

i wrote formula first conditioning vlookup , other index match, vlookup gave me last value of dates in checkinglist, , tried code : sub tempototal1()

    dim checkinglist worksheet     dim proximpedido worksheet     dim tear1 range     dim inicio range     dim tear2 range     dim saida range     dim diferença range     dim cell1 range     dim cell2 range     dim integer      set tear1 = worksheets("checkinglist").range("a2").currentregion set inicio = worksheets("checkinglist").range("e2").currentregion set tear2 = worksheets("proximopedido").range("a1").currentregion set saida = worksheets("proximopedido").range("b2").currentregion set diferença = worksheets("proximopedido").range("c2").currentregion    on error resume next  each cell1 in tear1 if tear1.cells.value = tear2.cells.value  each cell2 in inicio   if tear2.cells.value > saida.cells.value diferença.cells.value = inicio.cells.value - saida.cells.value  end if exit next cell2   end if exit next cell1         end sub 

thanks

setup 2 variables in code

  1. the first track cell location dim matchcell range
  2. the second track delta between source cell , match cell dim targetdelta double

now, loop through data on sheet: proximo pedido performing following logical steps

  1. calculate absolute delta between date on current cell , and date in checklist
  2. if delta less current value of targetdelta
  3. then update delta new value , record current address in matchcell variable
  4. continue looping
  5. after loop, know cell closest - stored in matchcell variable

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -