Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If date in range is before today mjones Excel Worksheet Functions 4 February 2nd 12 03:10 PM
MAX figure within a date range as a function of today()'s date irvine79 Excel Worksheet Functions 6 February 20th 07 03:28 PM
SUMIF within date range as a function of today()'s date irvine79 Excel Worksheet Functions 8 August 6th 06 05:55 PM
How do I add a range by date over 90 days older than today John DeLosa Excel Discussion (Misc queries) 4 February 16th 06 09:30 PM
How can I lock a date that has been established by the 'today ()'. ENT3041 Excel Discussion (Misc queries) 5 January 4th 05 10:59 PM


All times are GMT +1. The time now is 08:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"