Date Picker changing cell format

Sileed

New Member
Joined
May 21, 2009
Messages
1
Hi there,

Here's the issue I'm hoping someone can help with (I've pieced the solution together from some code I found here: http://www.contextures.com/xlDataVal14.html
That link explains how to insert a combo box in fields that are using data validation from a list (to take advantage of combobox feature over the default drop down in excel). I changed that code to insert MS Date Picker instead of a combobox if the data validation is set to Date

Here is my code:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
On Error GoTo errHandler

If Target.Count > 1 Then GoTo exitHandler

Set cboTemp = ws.OLEObjects("DPick")
On Error Resume Next
If cboTemp.Visible = True Then
  With cboTemp
    .Top = 10
    .Left = 10
    .LinkedCell = ""
    .Visible = False
    
  End With
End If

  On Error GoTo errHandler
  If Target.Validation.Type = 4 Then
    'if the cell contains a data validation date
    Application.EnableEvents = False
    
    Target.NumberFormat = "mm/dd/yyyy" 'format the cell to a date
    
    DPick.Value = Date 'default date picker to today if field is blank
    
    With cboTemp
      'show the Date Picker
      .Visible = True
      .Left = Target.Left
      .Top = Target.Top
      .Width = Target.Width + 15
      .Height = Target.Height + 5
      .LinkedCell = Target.Address
    End With
    cboTemp.Activate
    
  End If

exitHandler:
  Application.ScreenUpdating = True
  Application.EnableEvents = True
  Exit Sub
errHandler:
  Resume exitHandler

End Sub
I have 2 problems:

#1 If the field is blank, the date picker default to today (Great!) but if try to accept that value and move to a new cell the last cell remains blank
#2 once you choose a date value with the date picker, the cell shows a Data Validation error - it seems the value is a string (left justified) - selecting the cell, F2 then Enter corrects the issue.

Can anyone help with these issues please?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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