Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Highlighting Holidays in a Range with dates

Hello Guys,

I Have dates in the range D3:D369, from 1 jan to 31 dec (in that format).
Now I want to highlight the holidays in that range, but i'm having
difficulties with that.
I've created a collection, en i'm trying to use a For Each... Next to loop
through the range.

I also want this procedure to start automatically when i open up the
workbook, so in module 1 this doesn't seem to work, and I have no idea where
en how i should get this done...

What i've tried:

Sub Toef()
Dim hCollection As New Collection
Dim newyear, easter, daym, ascension, ... As String
Dim DateRange As Date
Dim allSheets As Worksheets
DateRange = allSheets.range("D3:D369").Select
newyear= "1 jan"
easter= "16 apr"
daym= "1 may"
ascension= "24 mei"
....
hCollection.Add (newyear)
hCollection.Add (easter)
hCollection.Add (daym)
hCollection.Add (ascension)
....

For Each DateRange In hCollection
DateRange.Item.Color = RGB(0, 255, 0)
Next DateRange.Item
End Sub

Thanks in advance guys,

Memento
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Highlighting Holidays in a Range with dates

A slightly different approach to yours. Your dates in A1 - A365 and you
holiday list in B1 - B8. then


Sub highlight()
Dim MyRange As Range
Set MyRange = Range("a1:a365")
For Each datecell In MyRange
datecell.Select
For x = 1 To 8
y = Cells(x, 2).Value
If datecell.Value = Cells(x, 2).Value Then
ActiveCell.Interior.ColorIndex = 7
End If
Next
Next
End Sub

Mike


"Memento" wrote:

Hello Guys,

I Have dates in the range D3:D369, from 1 jan to 31 dec (in that format).
Now I want to highlight the holidays in that range, but i'm having
difficulties with that.
I've created a collection, en i'm trying to use a For Each... Next to loop
through the range.

I also want this procedure to start automatically when i open up the
workbook, so in module 1 this doesn't seem to work, and I have no idea where
en how i should get this done...

What i've tried:

Sub Toef()
Dim hCollection As New Collection
Dim newyear, easter, daym, ascension, ... As String
Dim DateRange As Date
Dim allSheets As Worksheets
DateRange = allSheets.range("D3:D369").Select
newyear= "1 jan"
easter= "16 apr"
daym= "1 may"
ascension= "24 mei"
...
hCollection.Add (newyear)
hCollection.Add (easter)
hCollection.Add (daym)
hCollection.Add (ascension)
...

For Each DateRange In hCollection
DateRange.Item.Color = RGB(0, 255, 0)
Next DateRange.Item
End Sub

Thanks in advance guys,

Memento

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Highlighting Holidays in a Range with dates

Memento,

I like this one a bit better:-

Sub highlight()
Dim MyRange As Range
Dim HolRange As Range
Set MyRange = Range("a1:a365")
Set HolRange = Range("B1:B13")
For Each datecell In MyRange
datecell.Select
For Each holcell In HolRange
If datecell.Value = holcell.Value Then
ActiveCell.Interior.ColorIndex = 7
End If
Next
Next
End Sub

Mike

"Memento" wrote:

Hello Guys,

I Have dates in the range D3:D369, from 1 jan to 31 dec (in that format).
Now I want to highlight the holidays in that range, but i'm having
difficulties with that.
I've created a collection, en i'm trying to use a For Each... Next to loop
through the range.

I also want this procedure to start automatically when i open up the
workbook, so in module 1 this doesn't seem to work, and I have no idea where
en how i should get this done...

What i've tried:

Sub Toef()
Dim hCollection As New Collection
Dim newyear, easter, daym, ascension, ... As String
Dim DateRange As Date
Dim allSheets As Worksheets
DateRange = allSheets.range("D3:D369").Select
newyear= "1 jan"
easter= "16 apr"
daym= "1 may"
ascension= "24 mei"
...
hCollection.Add (newyear)
hCollection.Add (easter)
hCollection.Add (daym)
hCollection.Add (ascension)
...

For Each DateRange In hCollection
DateRange.Item.Color = RGB(0, 255, 0)
Next DateRange.Item
End Sub

Thanks in advance guys,

Memento

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Highlighting Holidays in a Range with dates

Hi,

You may use conditionnal formatting this way:

Sub HighLight()
With Range("D3:D369")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression,
Formula1:="=COUNT.IF("$H$3:$H$6";D3)=1"
.FormatConditions(1).Interior.Color = RGB(0, 255, 0)
End With
End Sub

Of course you need a range to store your holiday date (H3:H6 here).

It should be faster than a For Each Next statement.

Best regards from France,

Manu/


"Memento" a écrit dans le message de
news: ...
Hello Guys,

I Have dates in the range D3:D369, from 1 jan to 31 dec (in that format).
Now I want to highlight the holidays in that range, but i'm having
difficulties with that.
I've created a collection, en i'm trying to use a For Each... Next to loop
through the range.

I also want this procedure to start automatically when i open up the
workbook, so in module 1 this doesn't seem to work, and I have no idea
where
en how i should get this done...

What i've tried:

Sub Toef()
Dim hCollection As New Collection
Dim newyear, easter, daym, ascension, ... As String
Dim DateRange As Date
Dim allSheets As Worksheets
DateRange = allSheets.range("D3:D369").Select
newyear= "1 jan"
easter= "16 apr"
daym= "1 may"
ascension= "24 mei"
...
hCollection.Add (newyear)
hCollection.Add (easter)
hCollection.Add (daym)
hCollection.Add (ascension)
...

For Each DateRange In hCollection
DateRange.Item.Color = RGB(0, 255, 0)
Next DateRange.Item
End Sub

Thanks in advance guys,

Memento



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Highlighting Holidays in a Range with dates

Why not just use Conditional Formatting without VBA

Just use a formula of

=ISNUMBER(MATCH(D3,holiday_list,0))

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Memento" wrote in message
...
Hello Guys,

I Have dates in the range D3:D369, from 1 jan to 31 dec (in that format).
Now I want to highlight the holidays in that range, but i'm having
difficulties with that.
I've created a collection, en i'm trying to use a For Each... Next to loop
through the range.

I also want this procedure to start automatically when i open up the
workbook, so in module 1 this doesn't seem to work, and I have no idea
where
en how i should get this done...

What i've tried:

Sub Toef()
Dim hCollection As New Collection
Dim newyear, easter, daym, ascension, ... As String
Dim DateRange As Date
Dim allSheets As Worksheets
DateRange = allSheets.range("D3:D369").Select
newyear= "1 jan"
easter= "16 apr"
daym= "1 may"
ascension= "24 mei"
...
hCollection.Add (newyear)
hCollection.Add (easter)
hCollection.Add (daym)
hCollection.Add (ascension)
...

For Each DateRange In hCollection
DateRange.Item.Color = RGB(0, 255, 0)
Next DateRange.Item
End Sub

Thanks in advance guys,

Memento





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
National Holidays - Dates Emece Excel Discussion (Misc queries) 2 March 28th 10 11:20 PM
Calculating dates of holidays mikelee101[_2_] Excel Worksheet Functions 3 July 23rd 08 09:33 PM
Write Holidays between two dates? Nilay Excel 2003 Excel Worksheet Functions 6 December 8th 07 09:34 AM
How to exlude holidays from a range of dates Excel Dubai[_2_] Excel Discussion (Misc queries) 2 June 27th 07 12:44 PM
Dates with Holidays question HJ Excel Discussion (Misc queries) 1 March 31st 06 03:08 AM


All times are GMT +1. The time now is 10:57 AM.

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

About Us

"It's about Microsoft Excel"