Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Further improvement to this IP address sorting code.
Hi: I made an improvement to this code whereas it will cut in an * if
any IP section is missing. It results like this: ..232.152.15 *.232.152.015 222..152.15 222.*.152.015 222.232..15 222.232.*.015 222.232.152. 222.232.152.* At the same time, I made a slight stylistic improvement to the code to replace generic i and n variables with meaningful names. i as a loop counter went out of style back in, oh, 1980. I am posting here only the improved routine...copy the rest of the code from above posts. I hope you find this useful. Larry Brown Private Function FormatIPNum(IPNum As String, PadIt As Boolean) As Variant Dim Section_Num As Long Dim IP_Sect_Val As Long Dim Sections() As String Dim Fmt As String Const Dot As String = "." Const WildCard As String = "*" On Error GoTo BadNumber Sections() = Split(IPNum, Dot) If UBound(Sections()) < 3 Then Err.Raise 9 'must have 4 sections If PadIt Then Fmt = "000" For Section_Num = 0 To 3 On Error Resume Next IP_Sect_Val = CLng(Sections(Section_Num)) 'this will give an error if it's not a number If Err.Number = 0 Then If IP_Sect_Val < 0 Or IP_Sect_Val 255 Then Err.Raise 9 ElseIf IP_Sect_Val < 100 Then 'only numbers < 100 need changing Sections(Section_Num) = Format$(IP_Sect_Val, Fmt) End If Else Sections(Section_Num) = "*" End If Next Section_Num FormatIPNum = Join(Sections(), Dot) Exit Function BadNumber: FormatIPNum = CVErr(xlErrValue) Exit Function End Function |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Convert street address to zip code | Excel Worksheet Functions | |||
VB code to determine address of activeworkbook | Excel Discussion (Misc queries) | |||
How do I put the zip code in the address label? | Excel Discussion (Misc queries) | |||
Sorting IP Address | Excel Discussion (Misc queries) | |||
Sorting an Address List | Excel Worksheet Functions |