View Full Version : Automaticly add an amount


mdcory
07-06-2008, 06:37 PM
Hi all,
I am trying to figure out how to insert a number based a few things. I'll get right down to it.

This is what I have.

Column A Column B Column C
Description Amount Date entered

I need to find the latest date where column A = "house" then I need to see if it is greater than 14 days from today. If it is then a new row with column A house column B 178 and column C todays date. I also would like to have this run when it is opened. I have figured out how to find the max date with house but not how to get it to figure out the date thing.

Any help is greatly appreciated,
Thanks,
Matthew

ajetrumpet
07-07-2008, 07:56 PM
try this function:sub workbook_open

dim r as range, dte as date

for each r in range("c2", range("c2").end(xldown))
if r.offset(0, -2) = "house" then
if r > r.offset(-1, 0) then
dte = r
end if
end if
next r

if datediff("d", date(), dte) > 14 then
range("a2").end(xldown).offset(1, 0) = "house"
range("b2").end(xldown).offset(1, 0) = 178
range("c2").end(xldown).offset(1, 0) = date()
end if

end sub