Excel formula help

Copper Contributor


I have the following table. 


IP AddressCIDRNetmaskStart IPEnd IPBroadcast IP# of Hosts1st OCT2st OCT3st OCTIP Start IP EndCountryType
       12344 Device Managed Devices card readers


These are IP adressess (in A) and i have already broken them down into ranges - column K and L 

In a seperate field i want to compare the values in this table column H-L with an IP address (4 seperate columns e.g. to 4 columns 10 16 215 2) and find the exact row where the IP addrss is matching.

In other words - I want to create a search field where someone puts an IP address - it is then converted into 4 columns for the octets (i know how to do that) and then compared/matched with the 4 numbers in the table from column H-L by also making sure that the 4th searched number is within the range of K-L. I want to return Column M and N as a result. 

My goal is a searchable database where one can put in an IP and immadietely sees the country and the type/description without manually going through the list. 


I have tried 

=IF(AND(U15>=$K3, U15<=L3), IF(COUNTIF(H2:H6,R15)+COUNTIF(I2:I6,S15)+COUNTIF(J2:J6,T15)>=3, "Match", "Not Match"), "Not Match")


But this is not really the solution as it does not search in the whole column and it just returns Match or NO Match. Also tried with Vlookup but i am lost at this point.


Any help is appriciated, i am not great with functions in general unfortunately. 


Thanks a lot

8 Replies


Will the CIDR never be less than 24? It it were less than 24, the first three octets of the end IP could be different from that of the start IP.

best response confirmed by AttilaHetey (Copper Contributor)


On Excel 365, and if I understood the logic correctly, that could be

 (TEXTBEFORE($A12,".",3) = TEXTBEFORE($D$3:$D$8,".",3)) *
 (--TEXTAFTER($A12,".",3) >= --TEXTAFTER($D$3:$D$8,".",3)) *
 (--TEXTAFTER($A12,".",3) <= --TEXTAFTER($E$3:$E$8,".",3)),
 "no such" )


Man, this is perfect, thank you soo much. I thought that Excel cannnot comprehend IP ranges that is why i have broken it down to octets so i can make calculations with the last octet (that is a range) but your XLOOKUP somehow just works. I owe you a beer.
Sergei have answered with a working code, but thank you also for looking into this mate.
There is something wrong though.

If i search
It cannot find this in the range of
IP CIDR Netmask Start IP End IP 16

Do you know why this is the case? i see this with every 16 CIDR while it should be within the range.


Sorry, my logic was wrong, assumed first 3 octets are the same.

Taking into account that you already have Start IP and End IP formula could be

startIP,   $D$3:$D$9, endIP, $E$3:$E$9, type, $N$3:$N$9, ip, $A12,
decimallP, LAMBDA(v, SUM(TEXTSPLIT(v, ".")*256^{3,2,1,0}) ),
afterStart,BYROW( startIP, LAMBDA(v, decimallP(ip) >= decimallP(v)  ) ),
beforeEnd, BYROW( endIP, LAMBDA(v, decimallP(ip) <= decimallP(v) ) ),
XLOOKUP(1, afterStart*beforeEnd, type,"no such")


In it every IP address is converted into decimal form and we compare them not care about octets.

Didn't play with that, in general we may include into above formula calculation of Start/End IP as well using CIDR.

Thanks a lot man, this now works like a charm. I tested it and i think its fine now. Mind that i have over 7k IP ranges and will probably increase.
Thanks again

@AttilaHetey , you are welcome, glad to help