Solved

Holidays Between 2 Dates

Posted on 2013-01-29
7
301 Views
Last Modified: 2013-01-30
I found a bit of vb code that’s close to what I need here:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_23195737.html

I’ve listed it below but I’d like change it so that instead of returning a list dates in between the start and end dates, I want to return the list of holidays between the start and ends dates. I have a list of holiday dates in Row Y.

Private Sub CommandButton1_Click()

    startdate = Range("F11").Value
    enddate = Range("G11").Value
    daysbetween = enddate - startdate
    Results = "Day 1" & vbTab & startdate & vbCrLf
    For i = 1 To daysbetween
        nextdate = startdate + i
        Results = Results & "Day " & i & vbTab & nextdate & vbCrLf
    Next i
    MsgBox Results
End Sub

Open in new window

0
Comment
Question by:tracyms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38833911
Try this loop in your code. I have not tested it. If you have a problem then post your file and I can try to solve it.


for each cel in range("y1:y"& range("y" & rows.count).end(xlup).row)
if cel.value >= startdate and cel.value <= enddate then
 Results = Results & "Day " & cel.value - startdate & vbTab & nextdate & vbCrLf
endif
next cel
0
 
LVL 1

Author Comment

by:tracyms
ID: 38833927
I moved my holidays to row ak, starting in row ak2. I used the code below but it only shows the start date:


Private Sub CommandButton1_Click()

    startdate = Range("F11").Value
    enddate = Range("G11").Value
    daysbetween = enddate - startdate
    Results = "Day 1" & vbTab & startdate & vbCrLf
   
   
    For Each cel In Range("ak2:ak" & Range("ak" & Rows.Count).End(xlUp).Row)
If cel.Value >= startdate And cel.Value <= enddate Then
 Results = Results & "Day " & cel.Value - startdate & vbTab & nextdate & vbCrLf
End If
Next cel
   
   
   
    MsgBox Results
End Sub
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38834229
Can you upload a small sample excel file for testing?
0
Industry Leaders: 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!

 
LVL 1

Author Comment

by:tracyms
ID: 38834790
I've attached a test file.
holidays.xlsm
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 38834849
Put your cursor on one of the start dates or end dates and then run this macro

Private Sub CommandButton1_Click()

    startdate = ActiveCell.EntireRow.Cells(1).Value
    enddate = ActiveCell.EntireRow.Cells(2).Value
   
    For Each cel In Range("i2:i" & Range("i" & Rows.Count).End(xlUp).Row)
        If cel.Value >= startdate And cel.Value <= enddate Then
            Results = Results & "Day " & cel.Value - startdate & vbTab & cel & vbCrLf
        End If
    Next cel
   
    MsgBox Results
End Sub
0
 
LVL 1

Author Comment

by:tracyms
ID: 38836870
ssaqibh,

I've changed my request - if that's okay. Please see attached spreadsheet for details.
holidaysRevisited.xlsm
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38836916
This new request is significantly differently from the original request.

If the original request is appropriately answered the you should close this question and open another with the new request.

If there is something lacking in the solution with respect to the original request then continue to post here.
0

Featured Post

Independent Software Vendors: 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

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

738 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