Looking for guidance on comparisons

scotchtape

New Member
Joined
Mar 12, 2018
Messages
1
Hi,

I am not sure if I should call this a comparison, but I am not sure where to start. Here is what I am trying to do.

Lets say I have 1 column, column A.

In column A there are many rows of IP ranges:

10.10.1.0-10.10.127.255
10.10.128.0-10.10.255.255

If a A2 row is within a certain range, I would like to place text in B2 stating that the row is in "whatever"

I would have many rows. probably 60, and each row contains a unique IP range. I just need to assign them text in column b if they match a certain defined range. Below is just generic information.

A B
10.10.1.0-10.10.127.255 Apples 1
10.10.128.0-10.10.255.255 Apples 2
10.11.0.0-10.11.127.255 Apples 3
10.11.128.0-10.11.255.255 Orange


Where would I start?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
In column A there are many rows of IP ranges:

10.10.1.0-10.10.127.255
10.10.128.0-10.10.255.255


If you have all of this in A1,A2,A3... ect I think you are going to have a very hard time trying to determine if 10.10.1.1 in your reference cell will fall between your example 10.10.1.0 - 10.10.127.255 with just a formula, I feel quite sure this will need VBA unless you can structure you ranges differently and even then I am not sure how Excel will treat this 'Number' because it is an IP address.
 
Last edited:
Upvote 0
Are you familiar with Text to Columns?

I think a solution might be devised using Text to Columns and some formulas to convert the IP addresses to decimal integers. The conversion can be done without Text to Columns but the formulas would be long and have a lot of nesting.

An IP4 address is four fields separated by periods, ".". A valid field value must be between zero and 255 (&H00 to &HFF in VBA). We can convert an IP address to an integer by multiplying each field by a power of 255.

Say the IP address is "10.22.31.127". We can convert it to an integer with this equation:
=10 * 255^3 + 22 * 255^2 + 31 * 255^1 + 127 * 255^0

As an Excel formula and removing some unneeded exponents, the equation can be written as:
=Field1 * 255^3 + Field2 * 255^2 + Field3 *255 + Field4

If you convert all IP addresses to decimal integers, you can use greater than and less than comparisons to see if the ranges overlap or use a lookup table to populate the "whatevers".
 
Upvote 0
A
B
C
D
E
F
1
10.10.1.0-10.10.127.255
10
23
10.10.1.0
10.10.127.255
10.10.1.1
2
10.10.1.0
10.10.127.255
10.10.1.0

<tbody>
</tbody>
Sheet1


Worksheet Formulas
Cell
Formula
B1
=FIND("-",A1)
C1
=LEN(A1)
D1
=LEFT(A1,B1-1)
E1
=RIGHT(A1,C1-B1)
D2
=LEFT(A1,FIND("-",A1)-1)
E2
=RIGHT(A1,LEN(A1)-FIND("-",A1))

<tbody>
</tbody>

<tbody>
</tbody>


I showed you how I started with each simple formula to achieve my desired results and then how you can simple replace the cell reference with their formulas to build a larger formula and understand the order of operations. I used Conditional formatting on the last cell with a > reference and Excel was able to determine that 10.10.1.1 was larger than 10.10.1.0 hope this helps you, I will play around with the actual vlookup for the cell ranges at work tomorrow but you will probably have to sort the range after the formulas for Vlookup
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,320
Members
449,218
Latest member
Excel Master

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