Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Range Vlookup

Hi Every One,

I hope you all are doing well, I required your help to resolve my
issue in
excel.

On single worksheet i have two different sheet name as 1.IP Range 2.
Result.

Question:
EG:IP Range

Start IP End IP Area

192.168.1.4 195.182.254.254 AG
10.15.33.10 10.18.56.254 EMEA
10.128.33.5 10.132.40.60 AP

Here it will Continued as well.

On Result sheet i required result like:

IP Area

192.170.30.30 AG
194.168.10.20 AG
10.131.37.20 EMEA
10.170.255.255 NA
10.129.36.8 AP

I required result on area column. Here we have more than 50000 IP's
but very
difficult to find the area.

Could any one please help me on this issue. How i can resolve the
issue

Thanks in advance
Deen
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Range Vlookup


Are each of your areas unique or are there overlapping areas?

for eample
Area A : 190.0.0.0 to 199.255.255.255
Area B : 192.0.0.0 to 192.255.255.255

This code works for non-over lapping IP addresses. I would have to
modify the code to test for best match.

Sub SplitIP()

LookupIP = "192.170.30.30"

With Sheets("Sheet1")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For RowCount = 1 To LastRow
IP1 = Split(.Range("A" & RowCount), ".")
IP2 = Split(.Range("B" & RowCount), ".")
Area = .Range("C" & RowCount)
With Sheets("Sheet2")
For Index = 0 To 3
.Range("A" & RowCount).Offset(0, Index) = Val(IP1(Index))
.Range("E" & RowCount).Offset(0, Index) = Val(IP2(Index))
Next Index
.Range("I" & RowCount) = Area
End With
Next RowCount
End With

'sort IP address
With Sheets("Sheet2")
.Rows("1:" & LastRow).Sort _
Header:=xlNo, _
key1:=.Range("D1"), _
Order1:=xlAscending
.Rows("1:" & LastRow).Sort _
Header:=xlNo, _
key1:=.Range("A1"), _
Order1:=xlAscending, _
key2:=.Range("B1"), _
Order2:=xlAscending, _
key3:=.Range("C1"), _
Order3:=xlAscending

LookupIPArray = Split(LookupIP, ".")
Found = "Low"
RowCount = 1
Do While RowCount <= LastRow
For Index = 0 To 3
Field = Val(LookupIPArray(Index))
If .Range("A" & RowCount).Offset(0, Index) < Field Then
Exit For
End If

If Field < .Range("E" & RowCount).Offset(0, Index) Then
Found = "Match"
Area = .Range("I" & RowCount)
Exit For
End If

If Field .Range("E" & RowCount).Offset(0, Index) Then
Found = "High"
Exit For
End If

'required if IP exactly matches highest address in range
If Index = 3 Then
Found = "Match"
Area = .Range("I" & RowCount)
End If
Next Index
If Found = "High" Or _
Found = "Match" Then

Exit Do
End If
RowCount = RowCount + 1
Loop

If Found = "High" Then
MsgBox ("IP not found : " & LookupIP)
End If
If Found = "Match" Then
MsgBox ("Area : " & Area)
End If

End With

End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=198408

http://www.thecodecage.com/forumz

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vlookup range Randy Excel Discussion (Misc queries) 4 May 14th 10 03:59 PM
vlookup more than 2 range hitesh Excel Discussion (Misc queries) 5 May 30th 08 09:30 PM
vlookup for more than 2 range hitesh Excel Discussion (Misc queries) 6 May 28th 08 03:59 PM
Range to VLOOKUP as a Variable (range in another file) LuisE Excel Programming 3 December 2nd 07 03:22 PM
Vlookup where range changes Greg Excel Worksheet Functions 1 March 17th 06 11:41 PM


All times are GMT +1. The time now is 10:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"