Populate a cell with a date using DatePicker

John1953

New Member
Joined
Aug 28, 2019
Messages
2
When I select a cell to add a date using DatePicker drop down box, I select a date but nothing displays in the selected cell. The code I used is;

Private Sub Worksheet_SelectionChange(ByVal Target As Range)


With Sheet1.DTPicker1
.Height = 20
.Width = 20
If Not Intersect(Target, Range("A:A")) Is Nothing Then
.Visible = True
.Top = Target.Top
.Left = Target.Offset(0, 1).Left
Linkedcell = Target.Address
Else
.Visible = False
End If
End With
End Sub
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,618
Office Version
  1. 2007
Platform
  1. Windows
Hi John, welcome to the forum.

Try this

- Select cell on column A
- Select Date
- Or press Esc or any cell to hide dtpicker
- Or change date in the box and press Enter

Code:
Private Sub DTPicker1_Change()
  With Sheet1.DTPicker1
    ActiveCell.Value = .Value
    .Visible = False
    ActiveCell.Activate
  End With
End Sub


Private Sub DTPicker1_KeyPress(KeyAscii As Integer)
  If KeyAscii = 13 Then
    With Sheet1.DTPicker1
      ActiveCell.Value = .Value
      .Visible = False
      ActiveCell.Activate
    End With
  End If
End Sub


Private Sub DTPicker1_LostFocus()
  Sheet1.DTPicker1.Visible = False
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Not Intersect(Target, Range("A:A")) Is Nothing Then
    With Sheet1.DTPicker1
      .Visible = True
      .Top = Target.Top
      .Left = Target.Offset(0, 1).Left
    End With
  Else
    Sheet1.DTPicker1.Visible = False
  End If
End Sub
 
Last edited:

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,618
Office Version
  1. 2007
Platform
  1. Windows
I can't answer your private message because your mailbox is full
 

John1953

New Member
Joined
Aug 28, 2019
Messages
2
DanteAmor

I entered your code as shown and it works great, however, if I select a row (row number on the left) I get the following message;
Run-Time error '1004';
Application-Defined or Object-Defined error

Any ideas?
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,618
Office Version
  1. 2007
Platform
  1. Windows
DanteAmor

I entered your code as shown and it works great, however, if I select a row (row number on the left) I get the following message;
Run-Time error '1004';
Application-Defined or Object-Defined error

Any ideas?

Try this, add line in red.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
[COLOR=#ff0000]if target.count > 1 then exit sub[/COLOR]
  If Not Intersect(Target, Range("A:A")) Is Nothing Then
    With Sheet1.DTPicker1
      .Visible = True
      .Top = Target.Top
      .Left = Target.Offset(0, 1).Left
    End With
  Else
    Sheet1.DTPicker1.Visible = False
  End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,127,261
Messages
5,623,692
Members
415,983
Latest member
MusicMan

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
Top