View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
joeu2004 joeu2004 is offline
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