?
Solved

How do I display the name of an occassion between two dates?

Posted on 2011-10-27
9
Medium Priority
?
179 Views
Last Modified: 2012-05-12
Hi

I have two worksheets. In sheet "Date", I have a start date and an end date.
The second worksheet contains a list with all special occassions. There are two special occassions in one week.

As you can see from my screenshots, I'd like Excel to display the name(s) of
the special occassion(s) if it falls between the start and end date.

What is the easiest approach? With a formula or with VBA/custom function?
Thank you for your help. I've attached the spreadsheet to this post.
I appreciate your help.

Massimo
SpecialDays1.JPG
SpecialDays2.JPG
Special-Days.xls
0
Comment
Question by:Massimo Scola
  • 4
  • 3
  • 2
9 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 37037195
Try this formula

=INDEX('Special Days'!$A$1:$C$10,MATCH(1,SIGN((A2<='Special Days'!$A$1:$A$10)*(B2>='Special Days'!$A$1:$A$10)+(A2<='Special Days'!$B$1:$B$10)*(B2>='Special Days'!$B$1:$B$10)),0),3)

THIS IS AN ARRAY FORMULA AND YOU HAVE TO ENTER IT BY PRESSING

CTRL-ALT-ENTER
0
 
LVL 5

Expert Comment

by:Kannan K
ID: 37037201
Hi,

the easiest way is to do thru formula. you can do using IF function.

KK,
0
 
LVL 5

Expert Comment

by:Kannan K
ID: 37037216
Hi,

Use this simple formula to get your result

=IF(A2>='Special Days'!A3, IF(B2<='Special Days'!B3, 'Special Days'!C3,""),"")

KK,
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:Kannan K
ID: 37037225
Hi,

sorry, the above formula will work only on the current line. it won't work for range

KK,
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 37037233
This will clean up the #NA's

=IFERROR(INDEX('Special Days'!$A$1:$C$10,MATCH(1,SIGN((A2<='Special Days'!$A$1:$A$10)*(B2>='Special Days'!$A$1:$A$10)+(A2<='Special Days'!$B$1:$B$10)*(B2>='Special Days'!$B$1:$B$10)),0),3),"")
0
 

Author Comment

by:Massimo Scola
ID: 37037413
Thanks ssagibh

I tried the formula and it works. There are two holidays in one week: December 7 and December 8
Is it possible to display both?

0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 37037424
I spotted that later. I think I would prefer VBA to handle that aspect.
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 2000 total points
ID: 37042473
Try this sub

Sub holidayswithin()
Dim tws As Worksheet, sws As Worksheet
Dim trw As Range, srw As Range
Dim hstring As String
Set tws = Sheets("Date")
Set sws = Sheets("Special Days")
For Each trw In tws.Range("A2:A" & tws.Range("A2").End(xlDown).Row)
    hstring = ""
    For Each srw In sws.Range("A2:A" & tws.Range("A2").End(xlDown).Row)
        If (trw <= srw And trw.Offset(0, 1) >= srw) _
            Or (trw <= srw.Offset(0, 1) And trw.Offset(0, 1) >= srw.Offset(0, 1)) Then
                hstring = hstring & srw.Offset(0, 2) & ", "
        End If
    Next srw
    If Len(hstring) > 2 Then hstring = Left(hstring, Len(hstring) - 2)
    trw.Offset(0, 3) = hstring
Next trw
End Sub
0
 

Author Closing Comment

by:Massimo Scola
ID: 37138401
Thanks a lot. That really helped me!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question