I get this error only in specific spots, where it doesn't seem it should matter. For instance, In the first case, where I set timevals, the program runs fine. In the second case, where I set timevals again, I get the 424 Error.
I tried moving the Set timevals = time(mrCell.column) outside of my Select, as it does not need to be inside, calling the function for every single case (it can call it once, that's all that's needed..) but I am greeted with the error there as well. It only seems to work inside the Select, and only in certain areas.
'MsgBox .Value Set timevals = time(mrCell.column) time_start = timevals.item("start") MsgBox time_start time_stop = timevals.item("stop") MsgBox time_stop 'MsgBox .Value Case Is = "VM554 SAAnesSx - PtCare (Groups 12-14)" MsgBox .Value MsgBox mrCell.column Set timevals = time(mrCell.column) time_start = timevals.item("start") MsgBox time_start time_stop = timevals.item("stop") MsgBox time_stop MsgBox .Value
Here is the majority of the code.
Set Selected = Selection.Cells Dim timevals As Collection Dim time_start As String Dim time_stop As String For Each mrCell In Selected With mrCell Select Case .Value ' Here, we'll have to manually input the names (from the other macro that labeled everything..) Case Is = "VM569 AgAn Lab G 12-14" 'MsgBox .Value Set timevals = time(mrCell.column) time_start = timevals.item("start") MsgBox time_start time_stop = timevals.item("stop") MsgBox time_stop Case Is = "VM570 AgAn2" 'MsgBox .Value Set timevals = time(mrCell.column) time_start = timevals.item("start") MsgBox time_start time_stop = timevals.item("stop") MsgBox time_stop ' MsgBox .Value Case Is = "VM571 Therio" 'MsgBox .Value Set timevals = time(mrCell.column) time_start = timevals.item("start") MsgBox time_start time_stop = timevals.item("stop") MsgBox time_stop 'MsgBox .Value Case Is = "VM552 SAM2" 'MsgBox .Value Set timevals = time(mrCell.column) time_start = timevals.item("start") MsgBox time_start time_stop = timevals.item("stop") MsgBox time_stop 'MsgBox .Value Case Is = "VM597.3 PopTherio Lec" 'MsgBox .Value Set timevals = time(mrCell.column) time_start = timevals.item("start") MsgBox time_start time_stop = timevals.item("stop") MsgBox time_stop 'MsgBox .Value Case Is = "VM554 SAAnesSx - PtCare (Groups 12-14)" MsgBox .Value MsgBox mrCell.column Set timevals = time(mrCell.column) ' Error here time_start = timevals.item("start") MsgBox time_start time_stop = timevals.item("stop") MsgBox time_stop MsgBox .Value End Select End With Next
And here is the time function:
Function time(column As Long) 'Delcare Variables Dim c As New Collection Dim item As Variant Dim key As String Dim eg_start As String Dim eg_stop As String Dim ni_start As String Dim ni_stop As String Dim te_start As String Dim te_stop As String Dim el_start As String Dim el_stop As String 'instantiate them '8-9 eg_start = "8:09AM" eg_stop = "9:02AM" '9-10 ni_start = "9:09AM" ni_stop = "10:02AM" '10-11 te_start = "10:09AM" te_stop = "11:02AM" '11-12 el_start = "11:09AM" el_stop = "12:02PM" Select Case column Case Is = 8 key = "start" item = eg_start c.Add item, key key = "stop" item = eg_stop c.Add item, key Set time = c Case Is = 9 key = "start" item = ni_start c.Add item, key key = "stop" item = ni_stop c.Add item, key Set time = c Case Is = 10 key = "start" item = te_start c.Add item, key key = "stop" item = te_stop c.Add item, key Set time = c Case Is = 11 key = "start" item = el_start c.Add item, key key = "stop" item = el_stop c.Add item, key Set time = c Case Else key = "start" item = "N/A" c.Add item, key key = "stop" item = "N/A" c.Add item, key End Select MsgBox "goodbye" End Function
https://stackoverflow.com/questions/67377007/object-required-error-at-seemingly-random-locations May 04, 2021 at 07:34AM
没有评论:
发表评论