Picking date on calendar control to populate cell

OfficeUser

Well-known Member
Joined
Feb 4, 2010
Messages
542
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have code that will populate a cell when I select the date on the calendar control. Is there a way to allow me to select multiple dates and have the cell format such as for example: March 15, 16, 17, 18, 2011. Or even something similar.
Here is the current code:
Code:
Private Sub Calendar1_Click()
    ActiveCell.Value = CDbl(Calendar1.Value)
    ActiveCell.NumberFormat = "mm/dd/yyyy"
    ActiveCell.Select
End Sub
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Not Application.Intersect(Range("B5"), Target) Is Nothing Then
        Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
        Calendar1.Top = Target.Top + Target.Height
        Calendar1.Visible = True
        ' select Today's date in the Calendar
        Calendar1.Value = Date
    ElseIf Calendar1.Visible Then Calendar1.Visible = False
    End If
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I figured I would share how I made this work for myself. I altered my code to this:
Code:
Private Sub Calendar1_Click()
    If Range("B15").Value = "" Then
    Range("B15").Value = CDbl(Calendar1.Value)
    Else
    If Range("B16").Value = "" Then
    Range("B16").Value = CDbl(Calendar1.Value)
    Else
    If Range("B17").Value = "" Then
    Range("B17").Value = CDbl(Calendar1.Value)
    Else
    If Range("B18").Value = "" Then
    Range("B18").Value = CDbl(Calendar1.Value)
    Else
    If Range("B19").Value = "" Then
    Range("B19").Value = CDbl(Calendar1.Value)
    Else
    If Range("B20").Value = "" Then
    Range("B20").Value = CDbl(Calendar1.Value)
    Else
    If Range("B21").Value = "" Then
    Range("B21").Value = CDbl(Calendar1.Value)
    Else
    If Range("B22").Value = "" Then
    Range("B22").Value = CDbl(Calendar1.Value)
    Else
    If Range("B23").Value = "" Then
    Range("B23").Value = CDbl(Calendar1.Value)
    Else
    If Range("B24").Value = "" Then
    Range("B24").Value = CDbl(Calendar1.Value)
    Else
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
End Sub

There may be a better way to code this but I am still learning.
I then used this formula in cell B26:

=IF(B15="","",TEXT(B15,"m/dd, "))&IF(B16="","",TEXT(B16, "m/dd, "))&IF(B17="","",TEXT(B17, "m/dd, "))&IF(B18="","",TEXT(B18, "m/dd, "))&IF(B19="","",TEXT(B19, "m/dd"))&IF(AND(B15="", B16="", B17="", B18="", B19=""),""," of "&B25)

A similar formula is in cell B27. In cell B5 I placed this formula =B26. It now allows someone to select 5 dates (could be a hundred dates if I wanted) and it will populate one cell with all the dates. It ends up looking like this:

8/16, 8/17, 8/18, 8/19, 8/20 of 2011

;)
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,969
Members
449,059
Latest member
oculus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top