excel - Check if date falls between some range -
i have data similar to:
a1: id b1: start date c1: end date i have worksheet (call new) has
a1: id , b1: date i need find out if date id in new worksheet in previous worksheet. if date start date, end date or in between, want show there record exist.
solution here assuming more practical:
- a master sheet id, start date, end date (multiple rows)
- other sheets id , date (multiple rows)
- uses user defined function (udf) , id cell input
- one drawback need "calculate sheet" if other sheets has been updated
sample screenshots:
formula sheet1 d2: =findduplicates(a2)



code in module:
option explicit function findduplicates(orngid range) string dim sid string, dstart date, dend date, lcount long, swhere string dim ows worksheet, orngfound range, dfound date, sfirstfound string sid = orngid.text dstart = orngid.offset(0, 1).value dend = orngid.offset(0, 2).value lcount = 0 swhere = "" each ows in thisworkbook.worksheets ' find ids in other worksheeets if ows.name <> orngid.worksheet.name sfirstfound = "" set orngfound = ows.cells.find(what:=sid) if not orngfound nothing sfirstfound = orngfound.address ' keep searching until first found address met ' check dates, add if within dates dfound = orngfound.offset(0, 1).value if dstart <= dfound , dfound <= dend lcount = lcount + 1 if lcount = 1 swhere = swhere & lcount & ") '" & ows.name & "'!" & orngfound.address else swhere = swhere & vbcrlf & lcount & ") '" & ows.name & "'!" & orngfound.address end if end if set orngfound = ows.cells.find(what:=sid, after:=orngfound) loop until orngfound.address = sfirstfound end if end if next if lcount = 0 swhere = "not found" findduplicates = replace(swhere, "$", "") ' removes $ sign in addresses end function
Comments
Post a Comment