If Value matches on any date within month, no need of showing difference else show the minimum difference. Screen Shoot given below. Also have 2 type. If type is from sheet1, no need of showing type from Sheet 2 in output. If it is not available in Sheet 1, then show type from Sheet 2.