+ Reply to Thread
Results 1 to 3 of 3

Date picker cell

Hybrid View

donkey_uk Date picker cell 02-23-2018, 07:57 AM
kev_ Re: Date picker cell 02-23-2018, 08:35 AM
kev_ Re: Date picker cell 02-23-2018, 09:07 AM
  1. #1
    Forum Contributor
    Join Date
    05-13-2013
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    287

    Date picker cell

    HI Can anyone help

    I have a workbook with a date picker in a few cells with code, all works perfect, however when I click on the cell I can input any data and when I click out of the cell it errors out.

    if I click on the data picker dates its all ok.

    What I would like to do is lock the cell so only a date from the date picker will be shown, or even a msb box saying input error please input correct date


    Can anyone help me on theis. Here is the code that im using


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      
      With Sheet4.DTPicker2
        .Height = 20
        .Width = 20
        'If Not Intersect(Target, Range("A:A")) Is Nothing Then
        If Not Application.Intersect(Range("b20,b23,d26,e26,e27,d27,b49,b51"), Target) 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

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Date picker cell

    One trick I have employed to prevent the user being able to edit the cell directly:
    - insert an active-x Label
    - position it over the cell
    - make it the same size as the cell
    - make it transparent
    - make it move and resize with the cell

    Then to amend the cell value
    - attach a click event macro to the Label which triggers your date picker
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Date picker cell

    Here is a carrot for donkey

    Attached is simple example of blocking direct edit of a cell
    - the cell is named Cell_1 using a named range
    - avoids risk of rows or columns being inserted and changing the cell reference
    - a message pops up when user clicks on cell
    (in fact user is clicking on transparent label)
    - the event macro moves\sizes the label in line with the cell
    (I would not necessarily trigger it by every SelectionChange event - but the code is useful and the label must move when rows are inserted etc)

    The protected cell in the attached workbook is cell D2

    Private Sub Label1_Click()
        MsgBox "You cannot edit this cell directly"
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim shp1 As Shape:  Set shp1 = Me.Shapes("label1")
        Dim Cell_1 As Range:  Set Cell_1 = Range("Cell_1")
        With shp1
            .Top = Cell_1.Top
            .Left = Cell_1.Left
            .Height = Cell_1.Height
            .Width = Cell_1.Width
        End With
    End Sub
    Attached Files Attached Files
    Last edited by kev_; 02-24-2018 at 03:08 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Date picker within each cell question?
    By Johnny247 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-09-2016, 01:56 PM
  2. Date picker within each cell?
    By loccy in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 10-09-2016, 12:42 PM
  3. Replies: 0
    Last Post: 08-01-2015, 12:29 AM
  4. [SOLVED] Using date picker for specific cell
    By skhari in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2015, 04:25 PM
  5. [SOLVED] Date Picker in UserForm will not add value to specified cell
    By clapforthewolfman in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-04-2013, 01:18 PM
  6. How to format a cell to date picker?
    By Driaan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2013, 06:25 AM
  7. Still need help: Selecting next cell with Date Picker
    By BuzzT in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-30-2010, 02:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1