Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Looking for a formula that will convert IP address for sorting

I want a formula that will create an IP address that can be sorted properly

example:

Row A Row B
11.23.45.678 011.023.045.678
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Looking for a formula that will convert IP address for sorting

more examples


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"metelcom" wrote in message
...
I want a formula that will create an IP address that can be sorted properly

example:

Row A Row B
11.23.45.678 011.023.045.678


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,091
Default Looking for a formula that will convert IP address for sorting

He's looking for a method to change IP addresses into 12 character dotted
quads with leading zeros. All addresses will be in the form nnn.nnn.nnn.nnn
with leading zeroes in each group of 3. So, 1.22.33.4 becomes
001.022.033.004. Probably best handled by VBA


"Don Guillett" wrote in message
...
more examples


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"metelcom" wrote in message
...
I want a formula that will create an IP address that can be sorted
properly

example:

Row A Row B
11.23.45.678 011.023.045.678




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Looking for a formula that will convert IP address for sorting

More detail please and note: columns are A,B,C,D etc. across the top

Rows are 1,2,3,4,5 etc. down the side.

Your data is in columns or rows?


Gord Dibben MS Excel MVP

On Sun, 6 Jan 2008 08:55:06 -0800, metelcom
wrote:

I want a formula that will create an IP address that can be sorted properly

example:

Row A Row B
11.23.45.678 011.023.045.678


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Looking for a formula that will convert IP address for sorting

Sub leadingzeros()
lr = Cells(Rows.Count, "j").End(xlUp).Row
For Each c In Range("j2:j" & lr)
Select Case InStr(c, ".") - 1
Case 1: n = "00"
Case 2: n = "0"
Case 3: n = ""
Case Else
End Select
c.Value = n & c
Next c
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"metelcom" wrote in message
...
I want a formula that will create an IP address that can be sorted properly

example:

Row A Row B
11.23.45.678 011.023.045.678




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,480
Default Looking for a formula that will convert IP address for sorting

Hi

One way, assuming the IP addresses are in column A and the other columns on
sheet are empty

Copy Column A to Column B
Mark column BDataText to ColumnsNextOther delimiterchoose "." (without
the quotes)Finish
You will now have the 4 components of the IP address split into columns
B,C,D and E
In F1 enter
=TEXT(B1,"0000")&"."&TEXT(C1,"0000")&"."&TEXT(D1," 0000")&"."&TEXT(E1,"0000")
Copy down Column F as far as required.
Mark column FCopyMove cursor to B1Paste SpecialValues
Delete columns C:F

Sort your data on Column B

--

Regards
Roger Govier

"metelcom" wrote in message
...
I want a formula that will create an IP address that can be sorted
properly

example:

Row A Row B
11.23.45.678 011.023.045.678


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,059
Default Looking for a formula that will convert IP address for sorting

On Jan 6, 8:55*am, metelcom
wrote:
I want a formula that will create an IP address that can be sorted properly
example:
* * Row A * * * * * * * * * * * * *Row B
11.23.45.678 * * * * * * *011.023.045.678


First, "678" is not a valid octet of an IP address. Anyway....

Copy-and-Paste Special Value the range of cells in column A into
column B, then use the following macro (making sure the range in B is
still selected):

Sub convertIP()
For Each c In Selection
ip = Split(c.Value, ".", 4)
For i = 0 To 3
Select Case Len(ip(i))
Case 1: ip(i) = "00" & ip(i)
Case 2: ip(i) = "0" & ip(i)
Case Else
End Select
Next i
c.Value = Join(ip, ".")
Next c
End Sub

If you are not familiar with using macros, to enter the macro, press
alt+F11, click on InsertModule, then cut-and-paste the the macro text
above into the editing window. Return to the Excel worksheet. After
doing the cut-and-paste into column B, press alt+F8, select convertIP,
and click Run.

Caveat emptor: The above macro code is not bullet-proof. It gets
errors if the original IP address does not have at least 3 dots, for
example.

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,059
Default Looking for a formula that will convert IP address for sorting

On Jan 6, 10:54*am, I wrote:
use the following macro (making sure the range in B is still selected):


On second-thought, I think this is easier to use as a function. Enter
the function below according to the instructions in my previous
posting. Then, if A1 contains the IP address in dot-notation, put the
following into B1:

=convertIP(A1)

The function is:

Function convertIP(c) As String
ip = Split(c, ".", 4)
For i = 0 To 3
Select Case Len(ip(i))
Case 1: ip(i) = "00" & ip(i)
Case 2: ip(i) = "0" & ip(i)
Case Else
End Select
Next i
convertIP = Join(ip, ".")
End Function
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function to convert to email address? [email protected] Excel Worksheet Functions 4 November 12th 07 08:39 PM
Convert Relative to absolute address Yorke Excel Discussion (Misc queries) 6 October 25th 07 07:47 PM
how can i convert an email address to a web address Arvind Sikar Excel Worksheet Functions 3 October 3rd 06 08:06 PM
Sorting IP Address ggant Excel Discussion (Misc queries) 12 November 28th 05 05:53 PM
Sorting an Address List steve_g Excel Worksheet Functions 4 June 17th 05 06:36 PM


All times are GMT +1. The time now is 12:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"