+ Reply to Thread
Results 1 to 12 of 12

Unlock only if column date is equal to today's date +/- 2 days

  1. #1
    Registered User
    Join Date
    07-21-2015
    Location
    Orlando, FL
    MS-Off Ver
    2016
    Posts
    19

    Unlock only if column date is equal to today's date +/- 2 days

    Hello,

    I have zero experience with VBA but trying to learn. In the attached spread sheet I am trying to achieve the following through VBA. The sheet will be protected (blank password for the attached file)

    1. Lock all cells in a worksheet except for the column where the date in row 1 is equal to current date +/- 2 days. Basically, on any given date, should allow data entry only in one column within 2 days of the current date.

    2. I need the macro to work across all sheets in the workbook. The sheets could be named anything - not necessarily Sheet1 / Sheet2 etc.

    Thanks a bunch in advance for your efforts.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Unlock only if column date is equal to today's date +/- 2 days

    Put this code under the ThisWorkbook object:
    Please Login or Register  to view this content.
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Registered User
    Join Date
    07-21-2015
    Location
    Orlando, FL
    MS-Off Ver
    2016
    Posts
    19

    Re: Unlock only if column date is equal to today's date +/- 2 days

    Thank you, works perfectly. One item I forgot in my original post -

    The highlighted cells (B22 - B30) should always remain unlocked.

    Would you be kind enough to add this exception to the above code? I am attaching the file with your code in it.

    Thanks again.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Unlock only if column date is equal to today's date +/- 2 days

    Just those specific cells on that specific sheet, or any highlighted cells on any sheet?

  5. #5
    Registered User
    Join Date
    07-21-2015
    Location
    Orlando, FL
    MS-Off Ver
    2016
    Posts
    19

    Re: Unlock only if column date is equal to today's date +/- 2 days

    Sorry, should have been clearer.

    It will be the same set of cells in every sheet (B22 - B30).

    Thanks again.

  6. #6
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Unlock only if column date is equal to today's date +/- 2 days

    Adjust as follows:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-21-2015
    Location
    Orlando, FL
    MS-Off Ver
    2016
    Posts
    19

    Re: Unlock only if column date is equal to today's date +/- 2 days

    I am getting a "Compile error: Syntax error". I have attached a screen image to show you where it is generating the error -

    This is how I have the code entered at the moment. I am sure I am doing something wrong. Please advise. Thanks.

    For Each ws In ActiveWorkbook.Sheets
    With ws
    .Unprotect
    .Cells.Locked = True
    .Range("B22:B30)".Locked = False
    Col = .Cells(1, .Columns.Count).End(xlToLeft).Column
    Do Until Col = 0
    If IsDate(.Cells(1, Col).Value) Then
    If Abs(.Cells(1, Col).Value - Date) < 3 Then
    .Columns(Col).Locked = False
    End If
    End If
    Col = Col - 1
    Loop
    .Protect
    End With
    Next
    End Sub

  8. #8
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Unlock only if column date is equal to today's date +/- 2 days

    I'm afraid I can't see your attachment. Just shows up as a black box. Select Tools | References and let me know what references you have selected.

  9. #9
    Registered User
    Join Date
    07-21-2015
    Location
    Orlando, FL
    MS-Off Ver
    2016
    Posts
    19

    Re: Unlock only if column date is equal to today's date +/- 2 days

    Sorry, should have attached the file itself. Here it is...., if you run the macro you will see the compile error.

    Thanks
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Unlock only if column date is equal to today's date +/- 2 days

    It looks like you reversed the trailing ").
    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    07-21-2015
    Location
    Orlando, FL
    MS-Off Ver
    2016
    Posts
    19

    Re: Unlock only if column date is equal to today's date +/- 2 days

    Oops!!

    Sorry about that. Will fix and test. Thx.

  12. #12
    Registered User
    Join Date
    07-21-2015
    Location
    Orlando, FL
    MS-Off Ver
    2016
    Posts
    19

    Re: Unlock only if column date is equal to today's date +/- 2 days

    Works beautifuly... appreciate your prompt replies and your efforts.

+ 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. Calculate number of days between invoice date and today's date
    By JHerrick in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-30-2020, 03:53 PM
  2. Replies: 4
    Last Post: 05-08-2014, 10:13 AM
  3. Macro Count Days Between Today's Date and Column D
    By Gard5096 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-11-2012, 10:00 PM
  4. [SOLVED] Macros for: If Today's Date minus other date is greater than certain amount of days Then
    By lottidotti in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-24-2012, 04:46 PM
  5. Highlight Row If Equal to Today's Date
    By Kumara_faith in forum Excel General
    Replies: 2
    Last Post: 02-03-2010, 09:54 PM
  6. Remove Dates less than or equal to 30 days from Today’s Date
    By EJensen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-16-2009, 05:55 PM
  7. create a macro to alert me if today's date is within 5 days of expected delivery date
    By ashmcclure in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 09-25-2008, 05:51 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