Excel公式-> VBA:当月每个星期五的日期

时间:2018-08-01 19:15:14

标签: excel vba excel-vba excel-formula

我有@ScottCraner创建的当前公式,将其粘贴到单元格Q8中并拖到第12季度时,将使用本月每个星期五的日期填充单元格:

代码:

{
    "Sid": "AllowLaunchOnlyWithRequiredTags1",
    "Effect": "Deny",
    "Action": "ec2:RunInstances",
    "Resource": "arn:aws:ec2:us-east-1:accountid:instance/*",
    "Condition": {
        "Null": {"aws:RequestTag/dept": "true"}
    } }, {
    "Sid": "AllowLaunchOnlyWithRequiredTags2",
    "Effect": "Deny",
    "Action": "ec2:RunInstances",
    "Resource": "arn:aws:ec2:us-east-1:accountid:instance/*",
    "Condition": {
        "Null": {"aws:RequestTag/projectCode": "true"}
    } }

我正在尝试将其转换为VBA,因为我比公式更了解VBA。但是,我想知道这里是否有人可以提供帮助。

真的很感激

2 个答案:

答案 0 :(得分:4)

尝试使用此快速UDF。

...

if (ar.succeeded()) { 
    HttpResponse<JsonArray> result = ar.result();
    JsonArray body = result.body();
    System.out.println(body); 
    data.put("data", body.getJsonObject(0));
} else { 
    data.put("data", ar.cause().getMessage());
}

response.write(data.encode());
routingContext.response().end();

...

答案 1 :(得分:3)

这会迭代日期并将星期五放在Q8:Q12

Sub myFri()
    Dim OArr(1 To 5, 1 To 1) As Variant
    Dim k As Long
    k = 1
    Dim i As Long
    For i = DateSerial(Year(Date), Month(Date), 1) To DateSerial(Year(Date), Month(Date) + 1, 0)
        If Weekday(i, vbSunday) = 7 Then
            OArr(k, 1) = i
            k = k + 1
        End If
    Next i

    If k = 5 Then OArr(k, 1) = "-"

    Worksheets("Sheet1").Range("Q8:Q12").Value = OArr
    Worksheets("Sheet1").Range("Q8:Q12").NumberFormat = "mm/dd/yyyy"
End Sub