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

Leave a Comment