【问题标题】:vba finding weekend and choosing array responsevba 寻找周末并选择数组响应
【发布时间】:2016-01-19 16:59:57
【问题描述】:

如何让 b 列在周末显示“无”?代码运行,但我没有看到与没有选择案例的情况有什么不同。

Sub fixandresponse()
Dim count As Integer
Dim thedate As Date
Dim typesofproblems() As Variant
thedate = DateSerial(2014, 9, 1)

typesofproblems = Array("bought new hardware", "Phone Support", "New User Request", "Rent Hardware")


Select Case WeekdayName(thedate)

Case 1, 7: Instr(typesofproblems) = "none"
For count = 2 To 366

Range("B" & count) = typesofproblems(WorksheetFunction.RandBetween(0, 3))
Range("A" & count) = thedate

thedate = thedate + 1
Next

End Select
End Sub

【问题讨论】:

  • 如果我删除它运行的选择案例,它就不起作用。但我希望它在周末不说,我不知道怎么做。
  • 现在还说无效的过程调用

标签: vba date select weekday


【解决方案1】:

有几点:

(1) weekdayname() 不返回数字,它需要一个整数来指示您想要的一周中的哪一天,它返回一个带有实际名称的字符串,例如“Monday”。你想要的函数是 WeekDay()。

(2) 遍历 theDate,循环放错地方了。

(3) instr() 函数不会将值放入数组中,它会搜索一个字符串并将搜索字符串的起始位置作为整数返回。

试试这个:

Sub fixandresponse()

Dim count As Integer

Dim thedate As Date

Dim typesofproblems() As Variant

thedate = DateSerial(2014, 9, 1)

typesofproblems = Array("bought new hardware", "Phone Support", "New User Request", "Rent Hardware")
For count = 2 To 366
    Select Case Weekday(thedate)
            Case 1, 7
                Range("B" & count) = "none"
                Range("A" & count) = thedate
        Case Else
                Range("B" & count) = typesofproblems(WorksheetFunction.RandBetween(0, 3))
                Range("A" & count) = thedate
    End Select
    thedate = thedate + 1
Next



End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-09
    • 2015-12-29
    • 1970-01-01
    • 2019-01-22
    • 2018-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多