vba 查找周末并选择数组响应
vba finding weekend and choosing array response
如何让 b 列在周末显示 "none"?代码运行了,但我没有看到与没有 select 情况下的情况有什么不同。
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
几件事:
(1) weekdayname() 不是 return 数字,它需要一个整数来表示你想要的星期几,它 return 是一个带有实际名称的字符串,例如 "Monday"。你想要的功能是 WeekDay().
(2) 要遍历 theDate,循环在错误的地方。
(3) instr()函数不会将值放入数组,它会搜索一个字符串,return搜索字符串的起始位置作为一个整数。
试试这个:
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
如何让 b 列在周末显示 "none"?代码运行了,但我没有看到与没有 select 情况下的情况有什么不同。
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
几件事:
(1) weekdayname() 不是 return 数字,它需要一个整数来表示你想要的星期几,它 return 是一个带有实际名称的字符串,例如 "Monday"。你想要的功能是 WeekDay().
(2) 要遍历 theDate,循环在错误的地方。
(3) instr()函数不会将值放入数组,它会搜索一个字符串,return搜索字符串的起始位置作为一个整数。
试试这个:
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