Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lock range if date < today
Hi I need to lock cells in protected and shared workbook if cell value in
colA is 2 days less than today Eg. if A5=today()-2 then it should lock range A5:I5 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lock range if date < today
Try this snippet:
Sub DateLock() Dim varDate As Date Dim dif As Long varDate = Range("A5") If DateDiff("d", varDate, Date) 1 Then Range("A5:I5").Locked = True ActiveSheet.Protect Else Exit Sub End If End Sub Mike F "Kashyap" wrote in message ... Hi I need to lock cells in protected and shared workbook if cell value in colA is 2 days less than today Eg. if A5=today()-2 then it should lock range A5:I5 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lock range if date < today
It is not just 1 particular row.. How to do that?
"Mike Fogleman" wrote: Try this snippet: Sub DateLock() Dim varDate As Date Dim dif As Long varDate = Range("A5") If DateDiff("d", varDate, Date) 1 Then Range("A5:I5").Locked = True ActiveSheet.Protect Else Exit Sub End If End Sub Mike F "Kashyap" wrote in message ... Hi I need to lock cells in protected and shared workbook if cell value in colA is 2 days less than today Eg. if A5=today()-2 then it should lock range A5:I5 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lock range if date < today
This will loop down column A and check the dates. It assumes your data
starts on row 2, if it does not then adjust ARng to start on the proper row. Sub DateLock() Dim varDate As Date Dim dif As Long, LRow As Long Dim ARng As Range, c As Range LRow = Cells(Rows.Count, 1).End(xlUp).Row Set ARng = Range("A2:A" & LRow) 'assumes row 1 is headers For Each c In ARng varDate = Range("A" & c.Row) If DateDiff("d", varDate, Date) 1 Then ActiveSheet.Unprotect Range("A" & c.Row & ":I" & c.Row).Locked = True Else 'do nothing End If Next ActiveSheet.Protect End Sub Mike F "Kashyap" wrote in message ... It is not just 1 particular row.. How to do that? "Mike Fogleman" wrote: Try this snippet: Sub DateLock() Dim varDate As Date Dim dif As Long varDate = Range("A5") If DateDiff("d", varDate, Date) 1 Then Range("A5:I5").Locked = True ActiveSheet.Protect Else Exit Sub End If End Sub Mike F "Kashyap" wrote in message ... Hi I need to lock cells in protected and shared workbook if cell value in colA is 2 days less than today Eg. if A5=today()-2 then it should lock range A5:I5 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lock range if date < today
Getting type mismatch error
"Mike Fogleman" wrote: This will loop down column A and check the dates. It assumes your data starts on row 2, if it does not then adjust ARng to start on the proper row. Sub DateLock() Dim varDate As Date Dim dif As Long, LRow As Long Dim ARng As Range, c As Range LRow = Cells(Rows.Count, 1).End(xlUp).Row Set ARng = Range("A2:A" & LRow) 'assumes row 1 is headers For Each c In ARng varDate = Range("A" & c.Row) If DateDiff("d", varDate, Date) 1 Then ActiveSheet.Unprotect Range("A" & c.Row & ":I" & c.Row).Locked = True Else 'do nothing End If Next ActiveSheet.Protect End Sub Mike F "Kashyap" wrote in message ... It is not just 1 particular row.. How to do that? "Mike Fogleman" wrote: Try this snippet: Sub DateLock() Dim varDate As Date Dim dif As Long varDate = Range("A5") If DateDiff("d", varDate, Date) 1 Then Range("A5:I5").Locked = True ActiveSheet.Protect Else Exit Sub End If End Sub Mike F "Kashyap" wrote in message ... Hi I need to lock cells in protected and shared workbook if cell value in colA is 2 days less than today Eg. if A5=today()-2 then it should lock range A5:I5 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lock range if date < today
It is working fine in unshared workbook..
how to do with shared? "Kashyap" wrote: Getting type mismatch error "Mike Fogleman" wrote: This will loop down column A and check the dates. It assumes your data starts on row 2, if it does not then adjust ARng to start on the proper row. Sub DateLock() Dim varDate As Date Dim dif As Long, LRow As Long Dim ARng As Range, c As Range LRow = Cells(Rows.Count, 1).End(xlUp).Row Set ARng = Range("A2:A" & LRow) 'assumes row 1 is headers For Each c In ARng varDate = Range("A" & c.Row) If DateDiff("d", varDate, Date) 1 Then ActiveSheet.Unprotect Range("A" & c.Row & ":I" & c.Row).Locked = True Else 'do nothing End If Next ActiveSheet.Protect End Sub Mike F "Kashyap" wrote in message ... It is not just 1 particular row.. How to do that? "Mike Fogleman" wrote: Try this snippet: Sub DateLock() Dim varDate As Date Dim dif As Long varDate = Range("A5") If DateDiff("d", varDate, Date) 1 Then Range("A5:I5").Locked = True ActiveSheet.Protect Else Exit Sub End If End Sub Mike F "Kashyap" wrote in message ... Hi I need to lock cells in protected and shared workbook if cell value in colA is 2 days less than today Eg. if A5=today()-2 then it should lock range A5:I5 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lock range if date < today
Your type mismatch could arise from the fact that one or more of the data
is/are not a date? This won't run on a Shared workbook in any case. You cannot protect and unprotect sheets in a shared book. Whatever protection is on at time of sharing cannot be changed without un-sharing. Check out help on Features that are unavailable in shared workbooks Gord Dibben MS Excel MVP On Wed, 22 Apr 2009 12:34:20 -0700, Kashyap wrote: Getting type mismatch error "Mike Fogleman" wrote: This will loop down column A and check the dates. It assumes your data starts on row 2, if it does not then adjust ARng to start on the proper row. Sub DateLock() Dim varDate As Date Dim dif As Long, LRow As Long Dim ARng As Range, c As Range LRow = Cells(Rows.Count, 1).End(xlUp).Row Set ARng = Range("A2:A" & LRow) 'assumes row 1 is headers For Each c In ARng varDate = Range("A" & c.Row) If DateDiff("d", varDate, Date) 1 Then ActiveSheet.Unprotect Range("A" & c.Row & ":I" & c.Row).Locked = True Else 'do nothing End If Next ActiveSheet.Protect End Sub Mike F "Kashyap" wrote in message ... It is not just 1 particular row.. How to do that? "Mike Fogleman" wrote: Try this snippet: Sub DateLock() Dim varDate As Date Dim dif As Long varDate = Range("A5") If DateDiff("d", varDate, Date) 1 Then Range("A5:I5").Locked = True ActiveSheet.Protect Else Exit Sub End If End Sub Mike F "Kashyap" wrote in message ... Hi I need to lock cells in protected and shared workbook if cell value in colA is 2 days less than today Eg. if A5=today()-2 then it should lock range A5:I5 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
If date in range is before today | Excel Worksheet Functions | |||
MAX figure within a date range as a function of today()'s date | Excel Worksheet Functions | |||
SUMIF within date range as a function of today()'s date | Excel Worksheet Functions | |||
How do I add a range by date over 90 days older than today | Excel Discussion (Misc queries) | |||
How can I lock a date that has been established by the 'today ()'. | Excel Discussion (Misc queries) |