VBA 使用 WEEKDAY 的条件 IF 语句

VBA Conditional IF statement using WEEKDAY

Excel 列的屏幕截图

我正在尝试根据星期几编写条件 IF 语句。

我需要正确的值(取决于星期几)流入 AT 列。我想出的代码不起作用。 AT 中显示的只是 AK 值。我是 VBA 的新手,我肯定遗漏了一些东西。在此先感谢您的帮助。

Sub Weekday()

For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row

If Range("A" & i) = "=Weekday" Then 'This line of code doesn't work
     
Range("AT" & i).Value = Range("AL" & i).Value 'This line of code works
                                    
Else
Range("AT" & i).Value = Range("AK" & i).Value 'This line of code works

End If

Next

End Sub

更新:AK 和 AL 值都是小数,例如 506.468 或 348.286

返回星期几的 VBA 公式与工作表公式略有不同。尝试

If  Weekday(Range("A" & i).value, vbMonday) < 6 Then

Further information on this function and it's arguments.