Consulting

Results 1 to 3 of 3

Thread: disable cells based on time

  1. #1

    Exclamation disable cells based on time

    Hi,

    I need to disable certain cells based on time. I.e. if current date is in March,certain cells would be disabled. Similarly for April and October....

    I would appreciate your help.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    First use Format Cells to unlock all/relevant cells on the sheet. Then protect the sheet (though the code below does this). This code will lock cells as the months go by:
    [vba]Me.Protect userinterfaceonly:=True
    Select Case Month(Date)
    Case 4: Range("CertainCells").Locked = True 'April
    Case 6: Range("JuneCells").Locked = True 'June
    Case 8: Range("CertainOtherCells").Locked = True 'August
    End Select
    [/vba] but this code will lock only a certain range according to the month, but will unlock the others:
    [vba]Me.Protect userinterfaceonly:=True
    Range("CertainCells").Locked = Month(Date) = 4 'April
    Range("JuneCells").Locked = Month(Date) = 6 'June
    Range("CertainOtherCells").Locked = Month(Date) = 8 'August
    [/vba]When this code is run is up to you - perhaps in a worksheet event, or a workbook_open event.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3

    Thanks

    Thanks a lot

Posting Permissions

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