0
在Excel中,我有工作日命名的工作表。所以,我沒有周末也沒有特別的日子(節假日等)。我創建了一個函數:previous(x),其中x是工作的天數。我希望我的功能給我NX一天的日期(MM-DD格式),n是當前片的日子 編輯:對不起DAY1和MONTH1因爲日期和月份由VBAVB(A):循環查找上一張工作表
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
此使用功能正常工作一次(發現週末的前一天),但未能躍過兩洞(如週末+放假)
感謝您的幫助
個人注:請M $,通過類似於C#A – Coronier 2010-09-24 08:24:37