ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   crash on second pass of loop (https://www.excelbanter.com/excel-programming/339543-crash-second-pass-loop.html)

Rob

crash on second pass of loop
 
What I am trying to do is find the total amount of time my site goes down
from a spread sheet containing times and error messages. Each error message
stats with "ERROR". It all works when there is only one consecutive error,
but when it enters the loop it crashes on it's second pass. Any Suggestions?


Sub Total()

Dim ObjErrorString, ObjOkString
Dim ObjErrorCell, ObjErrorTime
Dim ObjOkCell, ObjOkTime
Dim ObjTotal

Set ObjErrorCell = Cells.Find(What:="ERROR", After:=ActiveCell,
SearchOrder:=xlByColumns, SearchDirection:=xlNext)
ObjErrorString = Left(ObjErrorCell.Offset(1, 0).Value, 5)
Do Until ObjErrorString < "ERROR"
ObjErrorCell = ObjErrorCell.Offset(1, 0)
Set ObjErrorString = Left(ObjErrorCell.Offset(1, 0).Value, 5)
Loop
ObjErrorCell.Select
Set ObjErrorTime = ActiveCell.Offset(0, -ActiveCell.Column + 1)
Set ObjOkCell = Cells.Find(What:="OK", After:=ActiveCell,
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)
ObjOkCell.Select
Set ObjOkTime = ActiveCell.Offset(0, -ActiveCell.Column + 1)
ObjTotal = ObjOkTime - ObjErrorTime
Range("E389").Value = ObjTotal

End Sub

Dave Peterson

crash on second pass of loop
 
You have a reply at your post in .misc

Rob wrote:

What I am trying to do is find the total amount of time my site goes down
from a spread sheet containing times and error messages. Each error message
stats with "ERROR". It all works when there is only one consecutive error,
but when it enters the loop it crashes on it's second pass. Any Suggestions?

Sub Total()

Dim ObjErrorString, ObjOkString
Dim ObjErrorCell, ObjErrorTime
Dim ObjOkCell, ObjOkTime
Dim ObjTotal

Set ObjErrorCell = Cells.Find(What:="ERROR", After:=ActiveCell,
SearchOrder:=xlByColumns, SearchDirection:=xlNext)
ObjErrorString = Left(ObjErrorCell.Offset(1, 0).Value, 5)
Do Until ObjErrorString < "ERROR"
ObjErrorCell = ObjErrorCell.Offset(1, 0)
Set ObjErrorString = Left(ObjErrorCell.Offset(1, 0).Value, 5)
Loop
ObjErrorCell.Select
Set ObjErrorTime = ActiveCell.Offset(0, -ActiveCell.Column + 1)
Set ObjOkCell = Cells.Find(What:="OK", After:=ActiveCell,
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)
ObjOkCell.Select
Set ObjOkTime = ActiveCell.Offset(0, -ActiveCell.Column + 1)
ObjTotal = ObjOkTime - ObjErrorTime
Range("E389").Value = ObjTotal

End Sub


--

Dave Peterson


All times are GMT +1. The time now is 12:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com