gpt4 book ai didi

vba - 如果是星期一,则添加 x y z

转载 作者:行者123 更新时间:2023-12-04 22:31:15 25 4
gpt4 key购买 nike

你能告诉我如何重组我的代码。目前,我在 D 列的底部(每天)添加一个日期 -1。但是,当它是星期一时,我需要将日期 -3、日期 -2 和日期 -1 添加到 D 列的底部。

这是我当前的代码:

y.Activate
With y1
Dim d As Long
d = Cells(Rows.Count, "D").End(xlUp).Row + 1 'there was an error in the code, I have changed the N to d
Cells(d, "D").Value = Date - 1
End With

我的假设是 IIf 语句?但话又说回来,我想它也需要一个循环。

谢谢

最佳答案

就在您的 Cells(d, "D").Value = Date - 1 之前行,输入:

If Weekday(Now()) = 2 Then
Cells(d, "D").Value = Date - 3
Cells(d + 1, "D").Value = Date - 2
Cells(d + 2, "D").Value = Date - 1
Else
Cells(d, "D").Value = Date - 1
End If
If Weekday(Now())将比较星期几(我相信默认情况下 1 是星期日)。因此,通过检查它是否为“2”,您就可以运行您想要的。我不确定这是否正是您的目标,但这将放置三个不同的日期值,从周五开始到周日结束。

可能不是最好的解决方案,但这是我对这个问题的理解。如果我离开让我知道,我会调整我的答案。

关于vba - 如果是星期一,则添加 x y z,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52609581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com