• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Check List IP in column (With Loop)

marreco

Member
Hi
I have a code to check IP's status, but i check multiple PI's in column.

I try a loop but my loop check one row only.

I want this loop go through all rows in column A.

Code:
Sub Ping_IP()
Dim ECHO As ICMP_ECHO_REPLY
Dim pos As Long
Dim success As Long

    With ActiveWorkbook.Worksheets("MySheetWith_IP")
        Row = 2
        Do
'#######--> begin code inside Loop <--#########
            If .Cells(Row, 1) <> "" Then
                If SocketsInitialize() Then
                    success = ping(([A2].Value), (Date), ECHO)
                    [B2].Value = GetStatusCode(success)
                    [C2].Value = ECHO.RoundTripTime & " ms"
                    [D2].Value = ECHO.DataSize & " bytes"
                If Left$(ECHO.Data, 1) <> Chr$(0) Then
                    pos = InStr(ECHO.Data, Chr$(0))
                    [E2].Value = Left$(ECHO.Data, pos - 1)
                End If
                    SocketsCleanup
                Else
                    MsgBox "Socket initialisation failure!!"
                End If
            End If
'#######--> end code inside Loop <--#########
            Row = Row + 1
        Loop Until .Cells(Row, 1) = ""
    End With

End Sub
My code based:
https://social.technet.microsoft.co...0f/ping-from-vba-in-excel?forum=officegeneral
Thank you!!
 
You have Row 2 hard coded for each columns (A:E) in your code inside the loop.
Replace with something like...
.Cells(Row, 1) for A2
.Cells(Row, 2) for B2

So on so forth.
 
Back
Top