Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 354
Default Loking Cells by Date

I have a chart where information is filled in every day. I would like the
cells to be available only "today." How do I have the cells lock for all
days that have passed, aas well as all of the days in the future?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Loking Cells by Date

This should work for you! I took the liberty of highlighting the unlocked
cells yellow. This will maximize readilbilty. If you don't want that then
just delete it out of the code.

Note: The sheet has to be protected for the Lock Property of the cells to
be active.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
If cell.Value = Date Then
cell.Locked = False
Else
cell.Locked = True
End If
Next cell
Sheets(wksName).Protect Password:=""

End Sub

If this helps please click "Yes" below.

--
Cheers,
Ryan


"Daniel" wrote:

I have a chart where information is filled in every day. I would like the
cells to be available only "today." How do I have the cells lock for all
days that have passed, aas well as all of the days in the future?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Loking Cells by Date

Oops! I forgot the hightlight part.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
With cell
If .Value = Date Then
.Locked = False
.Interior.Color = 3
Else
.Locked = True
.Interior.Color = xlNone
End If
End With
Next cell
Sheets(wksName).Protect Password:=""

End Sub

--
Cheers,
Ryan


"RyanH" wrote:

This should work for you! I took the liberty of highlighting the unlocked
cells yellow. This will maximize readilbilty. If you don't want that then
just delete it out of the code.

Note: The sheet has to be protected for the Lock Property of the cells to
be active.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
If cell.Value = Date Then
cell.Locked = False
Else
cell.Locked = True
End If
Next cell
Sheets(wksName).Protect Password:=""

End Sub

If this helps please click "Yes" below.

--
Cheers,
Ryan


"Daniel" wrote:

I have a chart where information is filled in every day. I would like the
cells to be available only "today." How do I have the cells lock for all
days that have passed, aas well as all of the days in the future?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Loking Cells by Date

Ryan, I had put in that code, but I could still not get it to work. I was
wondering if you had a minute to look at my worksheet that the original post
was for?

"RyanH" wrote:

Oops! I forgot the hightlight part.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
With cell
If .Value = Date Then
.Locked = False
.Interior.Color = 3
Else
.Locked = True
.Interior.Color = xlNone
End If
End With
Next cell
Sheets(wksName).Protect Password:=""

End Sub

--
Cheers,
Ryan


"RyanH" wrote:

This should work for you! I took the liberty of highlighting the unlocked
cells yellow. This will maximize readilbilty. If you don't want that then
just delete it out of the code.

Note: The sheet has to be protected for the Lock Property of the cells to
be active.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
If cell.Value = Date Then
cell.Locked = False
Else
cell.Locked = True
End If
Next cell
Sheets(wksName).Protect Password:=""

End Sub

If this helps please click "Yes" below.

--
Cheers,
Ryan


"Daniel" wrote:

I have a chart where information is filled in every day. I would like the
cells to be available only "today." How do I have the cells lock for all
days that have passed, aas well as all of the days in the future?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Loking Cells by Date

What did not work? Please explain. Did you get an error? If so, indicate
where in the code.
--
Cheers,
Ryan


"Spike" wrote:

Ryan, I had put in that code, but I could still not get it to work. I was
wondering if you had a minute to look at my worksheet that the original post
was for?

"RyanH" wrote:

Oops! I forgot the hightlight part.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
With cell
If .Value = Date Then
.Locked = False
.Interior.Color = 3
Else
.Locked = True
.Interior.Color = xlNone
End If
End With
Next cell
Sheets(wksName).Protect Password:=""

End Sub

--
Cheers,
Ryan


"RyanH" wrote:

This should work for you! I took the liberty of highlighting the unlocked
cells yellow. This will maximize readilbilty. If you don't want that then
just delete it out of the code.

Note: The sheet has to be protected for the Lock Property of the cells to
be active.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
If cell.Value = Date Then
cell.Locked = False
Else
cell.Locked = True
End If
Next cell
Sheets(wksName).Protect Password:=""

End Sub

If this helps please click "Yes" below.

--
Cheers,
Ryan


"Daniel" wrote:

I have a chart where information is filled in every day. I would like the
cells to be available only "today." How do I have the cells lock for all
days that have passed, aas well as all of the days in the future?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Loking Cells by Date

I put in that code that you had said, but nothing happened. I don't know if
i just don't remember if I need to change any of the code, but nothing
happened when I put in the code

"RyanH" wrote:

What did not work? Please explain. Did you get an error? If so, indicate
where in the code.
--
Cheers,
Ryan


"Spike" wrote:

Ryan, I had put in that code, but I could still not get it to work. I was
wondering if you had a minute to look at my worksheet that the original post
was for?

"RyanH" wrote:

Oops! I forgot the hightlight part.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
With cell
If .Value = Date Then
.Locked = False
.Interior.Color = 3
Else
.Locked = True
.Interior.Color = xlNone
End If
End With
Next cell
Sheets(wksName).Protect Password:=""

End Sub

--
Cheers,
Ryan


"RyanH" wrote:

This should work for you! I took the liberty of highlighting the unlocked
cells yellow. This will maximize readilbilty. If you don't want that then
just delete it out of the code.

Note: The sheet has to be protected for the Lock Property of the cells to
be active.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
If cell.Value = Date Then
cell.Locked = False
Else
cell.Locked = True
End If
Next cell
Sheets(wksName).Protect Password:=""

End Sub

If this helps please click "Yes" below.

--
Cheers,
Ryan


"Daniel" wrote:

I have a chart where information is filled in every day. I would like the
cells to be available only "today." How do I have the cells lock for all
days that have passed, aas well as all of the days in the future?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Loking Cells by Date

Put this code in your workbook_open event. This code will unlock all cells
with the date on your system and lock all other cells that have an earlier or
later date.

Option Explicit

Private Sub Workbook_Open()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
With cell
If .Value = Date Then
.Locked = False
.Interior.Color = 3
Else
.Locked = True
.Interior.Color = xlNone
End If
End With
Next cell
Sheets(wksName).Protect Password:=""

End Sub
--
Cheers,
Ryan


"Spike" wrote:

I put in that code that you had said, but nothing happened. I don't know if
i just don't remember if I need to change any of the code, but nothing
happened when I put in the code

"RyanH" wrote:

What did not work? Please explain. Did you get an error? If so, indicate
where in the code.
--
Cheers,
Ryan


"Spike" wrote:

Ryan, I had put in that code, but I could still not get it to work. I was
wondering if you had a minute to look at my worksheet that the original post
was for?

"RyanH" wrote:

Oops! I forgot the hightlight part.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
With cell
If .Value = Date Then
.Locked = False
.Interior.Color = 3
Else
.Locked = True
.Interior.Color = xlNone
End If
End With
Next cell
Sheets(wksName).Protect Password:=""

End Sub

--
Cheers,
Ryan


"RyanH" wrote:

This should work for you! I took the liberty of highlighting the unlocked
cells yellow. This will maximize readilbilty. If you don't want that then
just delete it out of the code.

Note: The sheet has to be protected for the Lock Property of the cells to
be active.

Sub LockDates()

Const wksName As String = "Sheet1"
Dim cell As Range

Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
If cell.Value = Date Then
cell.Locked = False
Else
cell.Locked = True
End If
Next cell
Sheets(wksName).Protect Password:=""

End Sub

If this helps please click "Yes" below.

--
Cheers,
Ryan


"Daniel" wrote:

I have a chart where information is filled in every day. I would like the
cells to be available only "today." How do I have the cells lock for all
days that have passed, aas well as all of the days in the future?

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
Clarification - how to automatically update cells with a date and date range Bekki Excel Discussion (Misc queries) 1 August 31st 10 03:18 AM
Split date from date time cells dd/mm/yyyy hh:mm. New cell dd/mm/y nigeo Excel Discussion (Misc queries) 3 April 1st 09 09:38 PM
Automatically update a cell with a date based on anther cells date GPR GUY Excel Discussion (Misc queries) 2 November 3rd 08 03:57 PM
About loking cells.. master777 Excel Worksheet Functions 1 July 17th 06 04:20 PM
Cell Blink or message if cells date = today date al007 Excel Programming 4 December 29th 05 01:39 PM


All times are GMT +1. The time now is 11:35 PM.

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"