Remove the last octet from an IP Address

meppwc

Well-known Member
Joined
May 16, 2003
Messages
604
Office Version
  1. 365
Platform
  1. Windows
I am trying to find a way of trimming away the last octet from an IP address in addition to the last period "."
The problem that I am running into is the last octet can be from 1 to 3 numbers in length

Example
10.127.17.1 -- result needed 10.127.17
10.127.17.22 -- result needed 10.127.17
10.127.17.454 -- result needed 10.127.17
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
sorry............just figured it out
=LEFT(A1,FIND("~",SUBSTITUTE(A1,".","~",3))-1)
 
Upvote 0
Thanks for your post. I iterated with your help and wanted to post what I came up with. Excuse the formatting, in a bit of a rush. I'll post a .png of the text and the text itself. If this solution is not completely correct, please post! If anyone wants to add the ones I am missing, that'd be great.

1688570436580.png



Input / Data: Output / Function: Function: What it does:
123.456.789.321 123.456.789 =LEFT(A2,FIND("~",SUBSTITUTE(A2,".","~",3))-1) Remove the last octet of the IP.
123.456.789.321 123.456 =LEFT(A3,FIND("~",SUBSTITUTE(A3,".","~",2))-1) Remove the last two octets of the IP.
123.456.789.321 123 =LEFT(A4,FIND("~",SUBSTITUTE(A4,".","~",1))-1) Remove the last three octets of the IP.
123.456.789.321 456.789.321 =RIGHT(A5,LEN(A5)-FIND("~",SUBSTITUTE(A5,".","~",1))-0) Remove the first octet of the IP.
123.456.789.321 789.321 =RIGHT(A6,LEN(A6)-FIND("~",SUBSTITUTE(A6,".","~",2))-0) Remove the first two octets of the IP.
123.456.789.321 321 =RIGHT(A7,LEN(A7)-FIND("~",SUBSTITUTE(A7,".","~",3))-0) Remove the first three octets of the IP.
123.456.789.321 789 =LEFT(RIGHT(A8,LEN(A8)-FIND("~",SUBSTITUTE(A8,".","~",2))-0),FIND(".",RIGHT(A8,LEN(A8)-FIND("~",SUBSTITUTE(A8,".","~",2))-0))-1) Show only the third octet.


Thanks again!
 

Attachments

  • 1688569541575.png
    1688569541575.png
    35.4 KB · Views: 81
  • 1688570227603.png
    1688570227603.png
    37.7 KB · Views: 81
Upvote 0
With 365 you can do it like
Fluff (version 1).xlsb
AB
1
2123.456.789.321123.456.789
3123.456.789.321123.456
4123.456.789.321123
5123.456.789.321456.789.321
Sheet5
Cell Formulas
RangeFormula
B2B2=TEXTBEFORE(A2,".",-1)
B3B3=TEXTBEFORE(A3,".",-2)
B4B4=TEXTBEFORE(A4,".",-3)
B5B5=TEXTAFTER(A5,".",1)
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

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