?
Solved

Holidays Between 2 Dates

Posted on 2013-01-29
7
Medium Priority
?
303 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
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…

752 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