Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7628919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:42:04+00:00 2026-05-31T05:42:04+00:00

I want to make a calendar in a sheet.It must be constructed taking initial

  • 0

I want to make a calendar in a sheet.It must be constructed taking initial date from another sheet, according to another column(hours) that are to spread among the working days.
So for example this:

    date    hours
17/02/2012  8
20/02/2012  50
20/02/2012  37
13/03/2012  110

should become:

date    hours
17/02/2012  8
20/02/2012  8
21/02/2012  8
22/02/2012  8
23/02/2012  8
24/02/2012  8
27/02/2012  8
28/02/2012  2
20/02/2012  8
21/02/2012  8
22/02/2012  8
23/02/2012  8
24/02/2012  3
13/03/2012  8
14/03/2012  8
15/03/2012  8
16/03/2012  8
19/03/2012  8
20/03/2012  8
21/03/2012  8
22/03/2012  8
23/03/2012  8
26/03/2012  8
27/03/2012  8
28/03/2012  8
29/03/2012  8
30/03/2012  6

The first day (17-Feb) is Friday and is filled by its next cell (8 hours). Next the macro has to take the second row, and starting from the 20-Feb(Monday), has to finish until the value (37 hours) is spread on next working days. In this way I have a workers ‘ Calendar for production. Someone can help me?
Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:42:06+00:00Added an answer on May 31, 2026 at 5:42 am

    This generates the output you seek with your example data.

    Option Explicit
    Sub GenerateCalendar()
    
      Dim DateCrnt As Date
      Dim DayOfWeekCrnt As Long
      Dim HoursToPlace As Long
      Dim RowDestCrnt As Long
      Dim RowSrcCrnt As Long
      Dim RowSrcLast As Long
      Dim SrcWork() As Variant
    
      ' Assume source data starts in row 2 of columns A and B of Worksheet Calendar 1
      With Worksheets("Calendar 1")
        ' Find last used row in column A
        RowSrcLast = .Cells(Rows.Count, "A").End(xlUp).Row
        SrcWork = .Range(.Cells(2, "A"), .Cells(RowSrcLast, "B")).Value
      End With
    
      ' SrcWork is now a 2D array containing the data from Calendar1.
      ' Dimension 1 holds the rows.  Dimension 2 holds to columns.
    
      ' Initialise control variable for SrcWork
      RowSrcCrnt = 1
      DateCrnt = SrcWork(RowSrcCrnt, 1)
      HoursToPlace = SrcWork(RowSrcCrnt, 2)
      RowSrcCrnt = 2
    
      ' Assume output data is to be placed in in Worksheet Calendar 2 in columns
      ' A and B starting at row 2
      RowDestCrnt = 2
    
      With Worksheets("Calendar 2")
        Do While True
          ' DateCrnt identifies the next date to output.
          ' HoursToPlace identifies the unplaced hours
          With .Cells(RowDestCrnt, 1)
            .Value = DateCrnt
            .NumberFormat = "ddd d mmm yyy"
          End With
          If HoursToPlace > 8 Then
            .Cells(RowDestCrnt, 2).Value = 8
            HoursToPlace = HoursToPlace - 8
          Else
            .Cells(RowDestCrnt, 2).Value = HoursToPlace
            HoursToPlace = 0
          End If
          RowDestCrnt = RowDestCrnt + 1
          If HoursToPlace = 0 Then
            ' No more hours to place from last row of SrcWork
            If RowSrcCrnt > UBound(SrcWork, 1) Then
              ' There are no used rows in SrcWork.  Finished
              Exit Do
            End If
            ' Extract next row from source data.
            DateCrnt = SrcWork(RowSrcCrnt, 1)
            HoursToPlace = SrcWork(RowSrcCrnt, 2)
            RowSrcCrnt = RowSrcCrnt + 1
          Else
            ' More hours to place. Set DateCrnt to the next weekday.
            Do While True
              DateCrnt = DateAdd("d", 1, DateCrnt)   ' Add 1 day to DateCrnt
              DayOfWeekCrnt = Weekday(DateCrnt)
              If DayOfWeekCrnt >= vbMonday And DayOfWeekCrnt <= vbFriday Then
                ' Have week day
                Exit Do
              End If
            Loop
          End If
        Loop
      End With
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a custom ASP.NET control that is a subclasse of System.Web.UI.WebControls.Calendar
I want to make a simple ASP.NET page that draws a months from a
I want to make an app...that can sync my iphone calender with google calendar..i
I have a table (a calendar, notably). I want to make the calendar not
I want to make Task in Google Calendar using Google Calendar API : c#.
I have style sheet with a class name changebackgroundcolor i want make change in
I want to make an etag that matches what Apache produces. How does apache
I want to make a table in SqlServer that will add, on insert, a
Well I don't actually want to make a calendar but I need a view
I want to make a a month view Calendar for iPad like the one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.