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

  • Home
  • SEARCH
  • 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 1096611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:18:28+00:00 2026-05-17T00:18:28+00:00

In Excel, i have sheets named after the working day. So, I don’t have

  • 0

In Excel, i have sheets named after the working day. So, I don’t have weekends nor special days (holidays and so). I’ve created a function : previous(x), with x the number of days worked. I want my function to give me the date (mm-dd format) of n-x day, n is the current sheet’s day
edit: sorry day1 and month1 because day and month are used by VBA

Function Previous(x As Integer) As String
currentSheet= ActiveSheet.Name
day1 = Right(currentSheet, 2)   'sheets' name convention is mm-dd
month1 = Left(currentSheet, 2)
nbLoop = 0
dayFound= 0
While dayFound < x
    day1= Format(day1 + 1, "dd")   'Call to 2 other functions that correctly decrement'
    day1= DecrementJ(day1)         'day and month'
    month1 = DecrementM(day1, month1)
    fPrec = month1 & "-" & day1
    On Error Resume Next
    Set wsSheet= Sheets(fPrec)
    If wsSheet Is Nothing Then
    Else                          'dont ask me why If Not wsS Is Nothing doesnt work'
        dayFound= dayFound+ 1
    End If
    nbLoop = nbLoop +1
    if nbLoop > 30 then goto Err:  'avoid infinite loop'
Wend
Previous= fPrec
Err:
End Function

This function correctly work once (it find the day before the weekend) but fail to jump over two holes (like a weekend + a holiday)

Thanks for your help

  • 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-17T00:18:29+00:00Added an answer on May 17, 2026 at 12:18 am

    Why so much effort? How about:

    calcdate = CDate(Year(Date) & "-" & ActiveSheet.Name) - x
    calcname = Format(calcdate, "mm-dd")
    For Each ws In Worksheets
        If ws.Name = calcname Then
            Previous = calcname
        End If
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an excel workbook with many sheets like sheet1, sheet2,... etc. How
I'll have an ASP.net page that creates some Excel Sheets and sends them to
I've created an excel sheet with Delphi 6. Now I have to add a
I have this Excel VB code, and everytime after it executes this line, it
I have an EXCEL sheet.it has various form-fields that are named as smrBgm133GallonsGross/ smrBgm167GallonsGross
I have read two excel sheets in two temp tables, #temp and #temp1 Replacing
I have an excel sheet full of times. They are formatted so that they
I have a DataSet populated from Excel Sheet. I wanted to use SQLBulk Copy
Every time I create a new excel sheet, I have to go in and
I have Excel add-in which I add so many class modules that it is

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.