在excel中创建一周中第一天,第二天或第三天的日期

时间:2018-12-06 10:57:55

标签: excel vba excel-vba

我需要确定给定数字是星期几,

例如我的年份= 2018日历周= 51并且数字= 3(这是一周的第3天)

日历第51周是12月。

一周从星期一到星期日开始

由于第51周的第3天是19日,因此结果应为“ 19/12/2018”

我们可以用Excel公式还是VBA宏吗?

在这方面的任何帮助深表感谢。

谢谢, 加内什

2 个答案:

答案 0 :(得分:0)

公然地从here复制,您可以使用Excel公式:

def h(lst):
    yield from lst
t = h([1, 2])
next(t)
next(t)
try:
    next(t)
except StopIteration:
    print('ST')
ST

所以=DATE(<YearNumber>, 1, -2) - WEEKDAY(DATE(<YearNumber>, 1, 3)) + <WeekNumber> * 7+ <DayNumber> -1 返回 2018年12月19日

答案 1 :(得分:0)

由vba获得。一个是宏,一个是udf。

$notification = array(
    'message' => 'Employee Information Created!',
    'alert-type' => 'success'
);

return redirect('/admin/employeemaintenance/show')
            ->with( $notification, 'Employee Information Created');

UDF

Sub getWeekDays()
    Dim vDB, vS(), vR()
    Dim y As Integer, s As Date, e As Date
    Dim i As Integer, k As Integer
    Dim n As Integer
    'y = Year
    y = InputBox("Input year : 2018  ")

    s = DateSerial(y, 1, 0)
    e = DateSerial(y + 1, 1, 0)
    n = e - s
    For i = 1 To n
        d = s + i
        If DatePart("ww", d, vbMonday) = DatePart("ww", d + 1, vbMonday) Then
        Else
            k = k + 1
            ReDim Preserve vR(1 To 2, 1 To k)
            vR(1, k) = DatePart("ww", d, vbMonday) & " Wk"
            If k = 1 Then
                vR(1, k) = DatePart("ww", s + 1, vbMonday) & " Wk"
                vR(2, k) = Format(s + 1, "dd.mm.yyyy") & "~" & Format(d, "dd.mm.yyyy")
            Else
                vR(2, k) = Format(d - 6, "dd.mm.yyyy") & "~" & Format(d, "dd.mm.yyyy")
            End If
        End If
    Next i
    Range("a1").CurrentRegion.Clear
    Range("a1").Resize(k, 2) = WorksheetFunction.Transpose(vR)
End Sub

enter image description here

相关问题