Go Premium for a chance to win a PS4. Enter to Win


Excel: Get third octet of an IP address

Posted on 2010-11-24
Medium Priority
Last Modified: 2012-05-10
Hello everybody

Can you guys help me find a way to get the third octet from an IP address?
What i basically need is everything that is in between (but not including) the second and third dot (.).


I should get the following:

Thank you :)
Question by:Advizor
  • 3
  • 3
  • 2
  • +2
LVL 30

Expert Comment

ID: 34204306
Would this help?
Sub Sample()
    Dim strIP As String, MyArray() As String
    strIP = ""
    MyArray = Split(strIP, ".")
    MsgBox MyArray(2)
End Sub

Open in new window

LVL 50
ID: 34204350
Here's a formula suggestion:


start in row 1 and copy down

cheers, teylyn
LVL 50
ID: 34204403
Building on SiddhartRout's VBA suggestion: if you want a dynamic VBA solution, you could try this user defined formula

Function Sample(strIP As String)
    Dim MyArray() As String
    MyArray = Split(strIP, ".")
    Sample = MyArray(2)
End Function

Open in new window

Copy and paste the code into a regular code module and then use


to calculate the result.
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

LVL 58

Accepted Solution

cyberkiwi earned 1500 total points
ID: 34204425

Won't get any #value #n/a errors if it is not a valid ip address, 0 instead
LVL 58

Expert Comment

ID: 34204451
Nevermind, please ignore the previous comment. Been working at it too long - there are better answers.
LVL 50
ID: 34204475
CK, nice one with the TRUNC. It does work for my data sample, so no need to apologize.
LVL 50

Expert Comment

by:barry houdini
ID: 34204646


regards, barry
LVL 50

Expert Comment

by:barry houdini
ID: 34204854



Author Comment

ID: 34204871
Thank you all for your suggestions.

I've managed to get something working from cyberkiwi's formula.
I ran into issues regarding international/regional settings when trying to use an unmodified version of cyberkiwi's.
Truncate expects a number, but on my danish version of Excel it does not see the preliminary result (on which to truncate) as a number. Yay! :/

Here is what I got to work:

=MID(B9;FIND("|";SUBSTITUTE(B9 & "..";".";"|";2))+1;FIND("|";SUBSTITUTE(B9 & "..";".";"|";3))-FIND("|";SUBSTITUTE(B9 & "..";".";"|";2))-1)

Thank you cyberkiwi (and all others as well) :)

Author Closing Comment

ID: 34204914
Had to modify the suggestion due to regional differences between the two computers.
LVL 58

Expert Comment

ID: 34207675
Though I am happy for the points, I thought the other formulas worked as well.
Barry has a knack for formulaes, and his two options are both amazing pieces of art.

While the 2nd one returns the wrong result when the fourth octet is 0, I think the 1st one works.


Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Quickbooks hosting can do wonders to your enterprise but considering the points elaborated in the article which will help you to better analyze the outcomes. So scan your business, its needs and then move to the new world of limitless benefits.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question