Vlookup IP Address and can Return Yes/No?

billtadz

New Member
Joined
Nov 20, 2020
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Similar to this old thread

But, I have a string in column A like below, outputs in D & E and two IPs in B&C.

Appreciate for a VB Script if possible, or is there another way aside from vlookup function?

SOURCEFirst IPSecond IPRESULT First IPRESULT Second IP
TEST 172.26.56.104172.26.56.104255.255.255.0YESNO
TEST172.26.56.105255.255.255.1NONO
TEST 172.26.56.106 255.255.255.2172.26.56.106255.255.255.2YESYES
TEST 255.255.255.3172.26.56.107255.255.255.3NOYES
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
VBA Code:
Option Explicit

Sub IPTest()
    Dim i As Long, lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 2 To lr
        If InStr(Range("A" & i), Range("B" & i)) > 0 Then
            Range("D" & i) = "Y"
        Else: Range("D" & i) = "N"
        End If
        If InStr(Range("A" & i), Range("C" & i)) > 0 Then
            Range("E" & i) = "Y"
        Else: Range("E" & i) = "N"
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox "complete"

End Sub
 
Upvote 0
Thank you for the quick response, how about if I add another column for third IP result.

SOURCEFirst IPSecond IPThird IPRESULT First IPRESULT Second IPRESULT Third IP
TEST 172.26.56.104172.26.56.104255.255.255.0YESNO
TEST172.26.56.105255.255.255.1NONO
TEST 172.26.56.106 255.255.255.2172.26.56.106255.255.255.2YESYES
TEST 255.255.255.3172.26.56.107255.255.255.3NOYES
TEST 255.255.255.3172.26.56.107255.255.255.3NOYES
TEST 172.26.56.106 255.255.255.2 SAMPLE 13.20.189.10172.26.56.106255.255.255.213.20.189.10YESYESYES
TEST 172.26.56.106 SAMPLE 13.20.189.10172.26.56.106255.255.255.213.20.189.10YESNOYES
TEST 255.255.255.2 SAMPLE 13.20.189.10172.26.56.106255.255.255.213.20.189.10NOYESYES
TEST 172.26.56.106 255.255.255.2 SAMPLE172.26.56.106255.255.255.213.20.189.10YESYESNO
 
Upvote 0
Follow the same format as shown for the first two items. But change the ranges over one column.

Option Explicit

VBA Code:
Sub IPTest()
    Dim i As Long, lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False

    For i = 2 To lr
        If InStr(Range("A" & i), Range("B" & i)) > 0 Then
            Range("E" & i) = "Y"
        Else: Range("E" & i) = "N"
        End If
        If InStr(Range("A" & i), Range("C" & i)) > 0 Then
            Range("F" & i) = "Y"
        Else: Range("F" & i) = "N"
        End If
         If InStr(Range("A" & i), Range("D" & i)) > 0 Then
            Range("G" & i) = "Y"
        Else: Range("G" & i) = "N"
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox "complete"

End Sub
 
Upvote 0
Ok got it, I want to highlight the cell of 'NO' to the colour red. How we modify the VB?

VBA Code:
Option Explicit

Sub IPTest()
    Dim i As Long, lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 2 To lr
        If InStr(Range("A" & i), Range("B" & i)) > 0 Then
            Range("E" & i) = "YES"
        Else: Range("E" & i) = "NO"
        End If
        If InStr(Range("A" & i), Range("C" & i)) > 0 Then
            Range("F" & i) = "YES"
        Else: Range("F" & i) = "NO"
        End If
        If InStr(Range("A" & i), Range("D" & i)) > 0 Then
            Range("G" & i) = "YES"
        Else: Range("G" & i) = "NO"
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox "complete"

End Sub
 
Upvote 0
and I wanted also the blank IP to return as blank in result.
 
Upvote 0
This will turn No cells Red. Still working on other issue. Bit sticky for me.

VBA Code:
Sub IPTest()
    Dim i As Long, lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False

    For i = 2 To lr
        If InStr(Range("A" & i), Range("B" & i)) > 0 Then
            Range("E" & i) = "Y"
        Else: Range("E" & i) = "N"
        Range("E" & i).Interior.ColorIndex = 3
        End If
        If InStr(Range("A" & i), Range("C" & i)) > 0 Then
            Range("F" & i) = "Y"
        Else: Range("F" & i) = "N"
        Range("F" & i).Interior.ColorIndex = 3
        End If
        If InStr(Range("A" & i), Range("D" & i)) > 0 Then
            Range("G" & i) = "Y"
        Else: Range("G" & i) = "N"
        Range("G" & i).Interior.ColorIndex = 3
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox "complete"

End Sub
 
Upvote 0
Solution
is there another way aside from vlookup function?
You could use standard worksheet functions as below and Conditional Formatting to highlight.

20 11 22.xlsm
ABCDEFG
1SOURCEFirst IPSecond IPThird IPRESULT First IPRESULT Second IPRESULT Third IP
2TEST 172.26.56.104172.26.56.104255.255.255.0YESNO 
3TEST172.26.56.105255.255.255.1NONO 
4TEST 172.26.56.106 255.255.255.2172.26.56.106255.255.255.2YESYES 
5TEST 255.255.255.3172.26.56.107255.255.255.3NOYES 
6TEST 255.255.255.3172.26.56.107255.255.255.3NOYES 
7TEST 172.26.56.106 255.255.255.2 SAMPLE 13.20.189.10172.26.56.106255.255.255.213.20.189.10YESYESYES
8TEST 172.26.56.106 SAMPLE 13.20.189.10172.26.56.106255.255.255.213.20.189.10YESNOYES
9TEST 255.255.255.2 SAMPLE 13.20.189.10172.26.56.106255.255.255.213.20.189.10NOYESYES
Check IP addresses
Cell Formulas
RangeFormula
E2:G9E2=IF(B2="","",IF(ISNUMBER(FIND(" "&B2&" "," "&$A2&" ")),"YES","NO"))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E2:G9Expression=E2="NO"textNO
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,742
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top