Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Making all past dates bold, looping

Hello guys,

I'm am trying to lock all cell, and make cell content bold until the date of
today is encountered. the range contains dates in the default date format
(this is European style date formatting, thus dd/mm/yyyy). However, it keeps
on looping...

any suggestions about this code?

Sub Button_Click()
Dim currentDate As Date
currentDate = Date

For Each c In Range("D5:D369")
Do Until c = currentDate
c.Font.Color = RGB(0, 255, 0)
c.Locked = True
c.Font.Bold = True
Loop
Next c
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Making all past dates bold, looping

You have a Do Loop that is doing nothing but cycling through the same
cell over and over again. No need for the Do Loop. Try this:
Sub Button_Click()
Dim currentDate As Date
currentDate = Date
For Each c In Range("D5:D369")
If Not c = currentDate Then
c.Font.Color = RGB(0, 255, 0)
c.Locked = True
c.Font.Bold = True
End If
Next c
End Sub

Memento wrote:
Hello guys,

I'm am trying to lock all cell, and make cell content bold until the date of
today is encountered. the range contains dates in the default date format
(this is European style date formatting, thus dd/mm/yyyy). However, it keeps
on looping...

any suggestions about this code?

Sub Button_Click()
Dim currentDate As Date
currentDate = Date

For Each c In Range("D5:D369")
Do Until c = currentDate
c.Font.Color = RGB(0, 255, 0)
c.Locked = True
c.Font.Bold = True
Loop
Next c
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Making all past dates bold, looping

And if you want to exit the sub once you have reached a cell that is
greater than or equal to the currentDate varaible, do something like
below. The first code I posted will cycle through ALL cells in the
specified range. Which one you use will depend on how your data is
structured. If the dates are not in ascending order and there is a
possibility that there is "old" data after the first occurrence of =
currentDate, then use the first code I posted. Else, use this code.
Sub Button_Click()
Dim currentDate As Date
currentDate = Date
For Each c In Range("D5:D18")
If Not c = currentDate Then
c.Font.Color = RGB(0, 255, 0)
c.Locked = True
c.Font.Bold = True
Else
Exit For
End If
Next c
End Sub
Memento wrote:
Hello guys,

I'm am trying to lock all cell, and make cell content bold until the date of
today is encountered. the range contains dates in the default date format
(this is European style date formatting, thus dd/mm/yyyy). However, it keeps
on looping...

any suggestions about this code?

Sub Button_Click()
Dim currentDate As Date
currentDate = Date

For Each c In Range("D5:D369")
Do Until c = currentDate
c.Font.Color = RGB(0, 255, 0)
c.Locked = True
c.Font.Bold = True
Loop
Next c
End Sub


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
recognizing dates past End of Month sk81222 Excel Discussion (Misc queries) 6 June 14th 06 03:43 PM
making cells bold thephoenix12 Excel Programming 1 June 23rd 05 06:34 PM
Past Due - Due Dates melarmor Excel Worksheet Functions 3 June 2nd 05 06:13 AM
How to set up past due notices based on dates Linn Excel Discussion (Misc queries) 3 March 18th 05 06:59 AM


All times are GMT +1. The time now is 03:18 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"