Show calendar date in specific column

sofas

Active Member
Joined
Sep 11, 2022
Messages
468
Office Version
  1. 2019
Platform
  1. Windows
Hello. How can I modify the code to show the date calendar when clicking on several cells? Now it only appears when clicking on cell b4. I want it to appear when clicking on cells b4:b100


VBA Code:
Private Sub Worksheet_selectionChange(ByVal Target As Range)
    
    Dim UnJour As Date
    If Target.Address = "$B$4" Then
        Application.EnableEvents = False
        Cancel = True
            UnJour = FormCal.Calendrier
            If UnJour <> 0 Then
                Target = Format(UnJour, "mm/dd/yyyy")
            Else
                Target = ""
            End If
        Selection.Offset(1, 0).Select
        Application.EnableEvents = True
    End If
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You can wrap around your code with an If condition. You can check your range with Not Intersect Is Nothing method:
VBA Code:
Private Sub Worksheet_selectionChange(ByVal Target As Range)
  If Not Intersect(Target, Range("B4:B100")) Is Nothing Then
    Dim UnJour As Date
    If Target.Address = "$B$4" Then
        Application.EnableEvents = False
        Cancel = True
            UnJour = FormCal.Calendrier
            If UnJour <> 0 Then
                Target = Format(UnJour, "mm/dd/yyyy")
            Else
                Target = ""
            End If
        Selection.Offset(1, 0).Select
        Application.EnableEvents = True
    End If
  End If
End Sub
 
Upvote 0
Solution
You can wrap around your code with an If condition. You can check your range with Not Intersect Is Nothing method:
VBA Code:
Private Sub Worksheet_selectionChange(ByVal Target As Range)
  If Not Intersect(Target, Range("B4:B100")) Is Nothing Then
    Dim UnJour As Date
    If Target.Address = "$B$4" Then
        Application.EnableEvents = False
        Cancel = True
            UnJour = FormCal.Calendrier
            If UnJour <> 0 Then
                Target = Format(UnJour, "mm/dd/yyyy")
            Else
                Target = ""
            End If
        Selection.Offset(1, 0).Select
        Application.EnableEvents = True
    End If
  End If
End Sub

Thank you, this code helped me to solve the problem.

Private Sub Worksheet_selectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4:B100")) Is Nothing Then
Dim UnJour As Date
Application.EnableEvents = False
Cancel = True
UnJour = FormCal.Calendrier
If UnJour <> 0 Then
Target = Format(UnJour, "mm/dd/yyyy")
Else
Target = ""
End If
Selection.Offset(0, 0).Select
Application.EnableEvents = True
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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