Solved

Holidays Between 2 Dates

Posted on 2013-01-29
7
295 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
  • 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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
 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now