Hi Jaemun,
Try this,
-----------------------------------------------------------
Dim DateCol As New Collection
Dim i As Long, CurMY As Long, NxtMY As Long, PrvMY As Long
Private Sub Calendar1_Click()
On Error Resume Next
'add dates to collection
DateCol.Add Format(Calendar1.Value, "#"), Format(Calendar1.Value, "#")
End Sub
Private Sub CommandButton1_Click()
Dim ResultDate, FullDateFmt, DayFmt
'if no dates selected then exit sub
If DateCol.Count = 0 Then Exit Sub
SortDate
FullDateFmt = Format(DateCol(1), "D MMM, YYYY")
For i = 1 To DateCol.Count - 1
FullDateFmt = Format(DateCol(i), "D MMM, YYYY")
DayFmt = Day(DateCol(i))
If i = 1 Then
If DateCol.Count > 1 Then
If SameMonthYear Then
ResultDate = DayFmt
Else
ResultDate = FullDateFmt
End If
End If
Else
If SameMonthYear Then
ResultDate = IIf(SameMonthYear1, ResultDate & ", " & DayFmt, ResultDate
& " and " & DayFmt)
Else
ResultDate = ResultDate & " and " & FullDateFmt
End If
End If
Next
If i = 1 Then
ActiveCell.Value = FullDateFmt
Else
ActiveCell.Value = ResultDate & " and " & Format(DateCol(i), "D MMM,
YYYY")
End If
End Sub
Function SortDate()
Dim i As Long, j As Long, vtemp
For i = 1 To DateCol.Count - 1
For j = i + 1 To DateCol.Count
If DateCol(i) > DateCol(j) Then
vtemp = DateCol(j)
DateCol.Remove j
DateCol.Add vtemp, vtemp, i
End If
Next j
Next i
End Function
Function SameMonthYear() As Boolean
GetMY
SameMonthYear = CurMY = NxtMY
End Function
Function SameMonthYear1() As Boolean
GetMY
SameMonthYear1 = CurMY = PrvMY
End Function
Sub GetMY()
CurMY = Month(DateCol(i)) & Year(DateCol(i))
NxtMY = Month(DateCol(i + 1)) & Year(DateCol(i + 1))
If i > 1 Then PrvMY = Month(DateCol(i - 1)) & Year(DateCol(i - 1))
End Sub
--------------------------------------------------------
Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/
http://in.geocities.com/shahshaileshs/
(Excel Add-ins Page)