4
2013
Working in Excel with IP Range – Tip
While working in excel for IP addresses, got a task to generate new IP address based on an existing one in order to configure a device, after doing some Googling find few articles on this topic, there are two good approaches to it,
1. Using excel formula like REPLACE, MIN, LEN, MID, CONCATENATE, calculate new IP range, for e.g.
Suppose your IP address is 10.76.192.0 and you like to generate new IP address as 10.76.(192+1).(0+15) then you can use following formula,
=CONCATENATE(REPLACE(A2, FIND(“.”,A2,FIND(“.”,A2)+1)+1, LEN(A2), MIN(255, MID(A2, FIND(“.”,A2,FIND(“.”,A2)+1)+1, LEN(A2)) + 1)),”.15″)
Similarly, if you just want to increase the last value in octet for e.g. 10.76.192.(0+15), then
=REPLACE(A2, FIND(“.”,A2,FIND(“.”,A2,FIND(“.”,A2)+1)+1)+1, LEN(A2), MIN(255, MID(A2, FIND(“.”,A2,FIND(“.”,A2,FIND(“.”,A2)+1)+1)+1, LEN(A2)) + 15))
If you like full control of each bit of IP address then solution is available at following link, http://stuart.weenig.com/2011/05/excel-and-ip-addresses.html
=VALUE(LEFT(A1,FIND(“.”,A1)-1))*2^24+VALUE(MID(A1,FIND(“.”,A1)+1,FIND(“.”,A1,FIND(“.”,A1)+1)-FIND(“.”,A1)-1))*2^16+VALUE(MID(A1,FIND(“.”,A1,FIND(“.”,A1)+1)+1,FIND(“.”,A1,FIND(“.”,A1,FIND(“.”,A1)+1)+1)-FIND(“.”,A1,FIND(“.”,A1)+1)-1))*2^8+VALUE(RIGHT(A1,LEN(A1)-FIND(“.”,A1,FIND(“.”,A1,FIND(“.”,A1)+1)+1)))
2. Using VBA function,
Reference: http://www.excelforum.com/excel-general/548005-how-do-create-a-formula-to-add-ip-addresses.html
a)
VBA Function-
Function NextIPAddress(IP As String) As String
Dim Arr As Variant
Arr = Split(IP, “.”)
Arr(UBound(Arr)) = Arr(UBound(Arr)) + 1
NextIPAddress = Join(Arr, “.”)
End Function
You can then call this from a worksheet cell with code like
=NextIPAddress(A1)
b)
Function NextIPAddress(IP As String) As String
Dim Arr As Variant
Dim V As Integer
Arr = Split(IP, “.”)
V = CInt(Arr(UBound(Arr)))
V = V + 1
If V Mod 4 = 0 Then
Arr(UBound(Arr)) = V
Else
V = V + 4 – (V Mod 4)
Arr(UBound(Arr)) = CStr(V)
End If
NextIPAddress = Join(Arr, “.”)
End Function
Other useful Reference: http://stackoverflow.com/questions/1111577/how-to-get-next-ip-in-range-from-excel

Leave a comment
Subscribe to this blog via Email
Old Posts
- November 2017 (3)
- October 2017 (4)
- September 2017 (2)
- May 2017 (1)
- April 2017 (1)
- July 2016 (3)
- May 2016 (1)
- April 2016 (1)
- February 2016 (2)
- January 2016 (1)
- October 2015 (1)
- September 2015 (1)
- August 2015 (1)
- July 2015 (2)
- June 2015 (3)
- April 2015 (1)
- March 2015 (1)
- December 2014 (1)
- September 2014 (2)
- April 2014 (1)
- January 2014 (3)
- October 2013 (2)
- September 2013 (2)
- August 2013 (4)
- July 2013 (1)
- June 2013 (2)
- May 2013 (5)
- April 2013 (3)
- March 2013 (1)
- February 2013 (9)
- January 2013 (11)
- December 2012 (14)
- November 2012 (3)
- October 2012 (4)
- July 2012 (2)
- June 2012 (3)
- May 2012 (2)
- April 2012 (8)
- March 2012 (6)
- February 2012 (3)
- January 2012 (1)
- December 2011 (5)
- November 2011 (8)
- October 2011 (5)
- September 2011 (3)
- August 2011 (3)
- July 2011 (3)
- May 2011 (1)
- November 2010 (1)
Tags
Calender
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
« Nov | ||||||
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
View Post by Categories
Recent Articles
- Setting up Always ON Availability Group in Multi Subnet Cluster – Recommendations
- Configuring Replication with Always ON Availability Group
- Login failed for user ‘DOMAIN\COMPUTER$’. Reason: Could not find a login matching the name provided. [CLIENT: ]
- Modern Servicing Model (Service Pack and Cumulative Updates) for SQL Server 2017 and onwards
- Fix: SSMS 2012 opening Debug window when pressing F5