JeffGrant
Well-known Member
- Joined
- Apr 7, 2021
- Messages
- 558
- Office Version
- 365
- Platform
- Windows
Hi All,
I have this code to loop through a column in a table to check if the string value for time is earlier than the current string value of now. Hever, I am getting a 424 error and I don't know why.
I am getting the Run-Time error 424: Object required from the For Each cell in column.DataBodyRange line.
This is my code:
can somebody please point me in the right direction. I suspect I am not declaring the cell variable correctly, but am not sure.
Thanks for your help.
I have this code to loop through a column in a table to check if the string value for time is earlier than the current string value of now. Hever, I am getting a 424 error and I don't know why.
I am getting the Run-Time error 424: Object required from the For Each cell in column.DataBodyRange line.
This is my code:
VBA Code:
Sub SkipEarlierTimes()
Dim ws As Worksheet
Dim tbl As ListObject
Dim column As ListColumn
Dim cell As Variant
Dim currentTime As Date
' Set the worksheet
Set ws = Sheet10
' Set the table
Set tbl = ws.ListObjects("API_Races_Next_Starts")
' Set the specific column
Set column = tbl.ListColumns(4)
' Get the current time
currentTime = Now
' Loop through each cell in the column
For Each cell In column.DataBodyRange
' Check if the time string is earlier than the current time
If TimeValue(CDate(cell.Value)) < TimeValue(CDate(currentTime)) Then
' If earlier, move to the next cell
'MsgBox "early, move on " & Format(cell.Value, "hh:mm")
Set cell = cell.Offset(1, 0)
Else
'MsgBox "Cell time is after now " & Format(cell.Value, "hh:mm")
Exit Sub
End If
Next cell
End Sub
can somebody please point me in the right direction. I suspect I am not declaring the cell variable correctly, but am not sure.
Thanks for your help.