Ping IP Address with VBA code and return results in Excel
You don't need code for this. Turn all the cells red, then add conditional formatting to make it green when you want.
Home > Conditional Formatting > New Rule > Use a formula...
=C2="Connected"
and format to green. If you want to do it in code, you can add some lines in your For Each loop
If Result = "Connected" Then
Cell.Offset(0,1).Font.Color = vbGreen
Else
Cell.Offset(0,1).Font.Color = vbRed
End If
To have this run automatically at certain intervals, check out this link.
Here's the relevant code:
Public dTime As Date
Dim lNum As Long
Sub RunOnTime()
dTime = Now + TimeSerial(0, 0, 10) 'Change this to set your interval
Application.OnTime dTime, "RunOnTime"
lNum = lNum + 1
If lNum = 3 Then
Run "CancelOnTime" 'You could probably omit an end time, but I think the program would eventually crash
Else
MsgBox lNum
End If
End Sub
Sub CancelOnTime()
Application.OnTime dTime, "RunOnTime", , False
End Sub
I would recommend including a ThisWorkbook.Save
line as I can't speak to how long this will run without crashing, and I would imagine you could see problems if you left it for days at a time.