I am writing a code for ping tester.
In sheet one it keeps on pinging devices continuously and displays the ping time in column B. When any device becomes unreachable it shows the last ping time and duration of unreachability in next column. But when that device becomes reachable it sends the duration of reachability (report) to next sheet and start showing that device reachable.
I want to open the report sheet while macro is running in sheet1.
If I'm using select (as in code) it forces me to sheet1 but without this if I open sheeet2 the pinging time started typing in sheet2.
Sub Do_ping()
With ActiveWorkbook.Worksheets(1)
Worksheets("sheet1").Select
row = 2
Do
If .Cells(row, 1) <> "" Then
If IsConnectible(.Cells(row, 1), 2, 100) = True Then
Worksheets("sheet1").Select
If Cells(row, 3).Value = nul Then
Cells(row, 1).Interior.Color = RGB(0, 255, 0)
Cells(row, 1).Font.FontStyle = "bold"
Cells(row, 1).Font.Size = 14
Cells(row, 2).Interior.Color = RGB(0, 255, 0)
Cells(row, 2).Value = Time
Else
Worksheets("sheet1").Select
Cells(row, 1).copy Sheets("sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Cells(row, 2).copy Sheets("sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
Cells(row, 5).copy Sheets("sheet2").Range("c" & Rows.Count).End(xlUp).Offset(1, 0)
Cells(row, 1).Interior.Color = RGB(0, 255, 0)
Cells(row, 1).Font.FontStyle = "bold"
Cells(row, 1).Font.Size = 14
Cells(row, 2).Interior.Color = RGB(0, 255, 0)
Cells(row, 2).Value = Time
Cells(row, 5).ClearContents
End If
'Call siren
Else:
'Cells(Row, 2).Formula = "=NOW()-" & CDbl(Now())
'Cells(Row, 1).Interior.Color = RGB(255, 0, 0)
Worksheets("sheet1").Select
Cells(row, 3).Value = DateDiff("d", Cells(row, 2), Now())
'Time Difference. First set the format in cell.
Cells(row, 4).NumberFormat = "hh:mm:ss"
'/calculate and update
Cells(row, 4).Value2 = Now() - Cells(row, 2)
Cells(row, 5).Value = Hour(Cells(row, 4).Value2) * 3600 + Minute(Cells(row, 4).Value2) * 60 + Second(Cells(row, 4).Value2)
If Cells(row, 5).Value > 120 Then
Worksheets("sheet1").Select
Cells(row, 1).Interior.ColorIndex = 3
Cells(row, 2).Interior.ColorIndex = 3
Cells(row, 3).Interior.ColorIndex = 3
Cells(row, 4).Interior.ColorIndex = 3
Else
Worksheets("sheet1").Select
Cells(row, 1).Interior.ColorIndex = 40
Cells(row, 2).Interior.ColorIndex = 40
Cells(row, 3).Interior.ColorIndex = 40
Cells(row, 4).Interior.ColorIndex = 40
End If
End If
End If
row = row + 1
Loop Until .Cells(row, 1) = ""
End With
End Sub