Note: The other languages of the website are Google-translated. Back to English
English English

Comment trier rapidement l'adresse IP de bas en haut dans Excel?

En général, nous utilisons la fonction Trier pour trier la chaîne dans Excel. Mais s'il y a des adresses IP nécessaires pour trier, l'ordre de tri peut être erroné en utilisant la fonction Trier directement comme illustré ci-dessous. Maintenant, j'ai quelques moyens de trier les adresses IP rapidement et correctement dans Excel.

Mauvaise fonction de tri par tri Tri correct
doc tri ip 1 doc tri ip 2

Trier l'adresse IP par formule

Trier l'adresse IP par VBA

Trier l'adresse IP par texte dans les colonnes


Trier l'adresse IP par formule

Utilisez une formule pour remplir l'adresse IP puis trier.

1. Sélectionnez une cellule adjacente à l'adresse IP et tapez cette formule

=TEXT(LEFT(A1,FIND(".",A1,1)-1),"000") & "." & TEXT(MID(A1,FIND( ".",A1,1)+1,FIND(".",A1,FIND(".",A1,1)+1)-FIND(".",A1,1)-1),"000") & "." & TEXT(MID(A1,FIND(".",A1,FIND(".",A1,1)+1)+1,FIND(".",A1, FIND(".",A1,FIND(".",A1,1)+1)+1)-FIND(".",A1,FIND(".",A1,1)+1)-1), "000") & "." & TEXT(RIGHT(A1,LEN(A1)-FIND(".",A1,FIND(".",A1,FIND( ".",A1,1)+1)+1)),"000")

appuyer Entrer et faites glisser la poignée de remplissage sur les cellules pour appliquer cette formule.
doc tri ip 3

2. Copiez les résultats de la formule et collez-les comme valeur dans la colonne suivante. Voir la capture d'écran:

doc tri ip 4
doc tri ip 5

3. gardez la valeur collée sélectionnée et cliquez sur Données > Trier de A à Z.
doc tri ip 6

4. dans le Trier Waring dialogue, garde Élargir la sélection vérifié.
doc tri ip 7

5. cliquez sur Sort. Maintenant, les adresses IP ont été triées de bas en haut.
doc tri ip 2

Vous pouvez supprimer les colonnes d'assistance.


Trier l'adresse IP par VBA

Voici un code VBA qui peut également vous aider.

1. presse Alt + F11 touches pour activer Microsoft Visual Basic pour applications fenêtre.

2. Cliquez insérer > Module, copiez et collez le code dans le script vide.

VBA: remplir l'adresse IP

Sub FormatIP()
'UpdatbyExtendoffice20171215
    Dim xReg As New RegExp
    Dim xMatches As MatchCollection
    Dim xMatch As Match
    Dim xRg As Range
    Dim xCell As Range
    Dim I As Long
    Dim xArr() As String
    On Error Resume Next
    Set xRg = Application.InputBox("Select cells:", "KuTools For Excel", Selection.Address, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    With xReg
        .Global = True
        .Pattern = "\d{1,3}\.+\d{1,3}\.+\d{1,3}\.+\d{1,3}"
        For Each xCell In xRg
            Set xMatches = .Execute(xCell.Value)
            If xMatches.Count = 0 Then GoTo xBreak
            For Each xMatch In xMatches
                xArr = Split(xMatch, ".")
                For I = 0 To UBound(xArr)
                    xArr(I) = Right("000" & xArr(I), 3)
                    If I <> UBound(xArr) Then
                        xArr(I) = xArr(I) & "."
                    End If
                Next
            Next
            xCell.Value = Join(xArr, "")
xBreak:
        Next
    End With
End Sub

doc sort ip 8

3. Then click Tools > Reference, and check Microsoft VBScript Regular Expressions 5.5 in the popping dialog.

doc sort ip 9
doc sort ip 10

4. Click OK and press F5 key, a dialog pops out to remind you to select a range to work.
doc sort ip 11

5. Click OK. Then the IP addresses have been filled with zero.

6. Select the IP addresses and click Data > Sort A to Z to sort them.


Sort IP address by Text to Columns

Actually, the Text to Columns feature can do you a favor in Excel too.

1. Select the cells you use, and click Data > Text to Columns. See screenshot:
doc sort ip 12

2. In the Convert Text to Columns Wizard dialog, do as below:

Check Delimited, and click Next;

Check Other and type . into the textbox, and click Next;

Select a cell next to the IP address to place the result. Click Finish.

doc sort ip 13
doc sort ip 14
doc sort ip 15

3. The select all cells containing the IP addresses and the split cells, and click Data > Sort.
doc sort ip 16

4. In the Sort dialog, clicking Add level to sort data from column B to E (the split cells). See screenshot:
doc sort ip 17

5. Click OK. Now the columns have been sorted.
doc sort ip 18



The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Why does the formula not work for the last octet? It adds zeros to the 3rd octet but not the last? So frustrating.
This comment was minimized by the moderator on the site
I have tested the formula before I post it, it can work for the last octer. Have you checked the formula you pasted is correct?
This comment was minimized by the moderator on the site
la formule traduite en Francais :
=TEXTE(GAUCHE(I6;TROUVE(".";I6;1)-1);"000") & "." & TEXTE(STXT(I6;TROUVE( ".";I6;1)+1;TROUVE(".";I6;TROUVE(".";I6;1)+1)-TROUVE(".";I6;1)-1);"000") & "." & TEXTE(STXT(I6;TROUVE(".";I6;TROUVE(".";I6;1)+1)+1;TROUVE(".";I6; TROUVE(".";I6;TROUVE(".";I6;1)+1)+1)-TROUVE(".";I6;TROUVE(".";I6;1)+1)-1); "000") & "." & TEXTE(DROITE(I6;NBCAR(I6)-TROUVE(".";I6;TROUVE(".";I6;TROUVE( ".";I6;1)+1)+1));"000")
This comment was minimized by the moderator on the site
Merci pour la traduction !
This comment was minimized by the moderator on the site
thank you, very useful !
This comment was minimized by the moderator on the site
This is great! Very much appreciated. It would be nice to add to the VB code to reverse (put back) the IP's in the original format (without the extra leading 0's) after having sorted them. :) I would be very interested in that where you can run this script, sort results, then revert back to original format.
This comment was minimized by the moderator on the site
Traducido al español:
=TEXTO(IZQUIERDA(A1,ENCONTRAR(".",A1,1)-1),"000") & "." & TEXTO(EXTRAE(A1,ENCONTRAR( ".",A1,1)+1,ENCONTRAR(".",A1,ENCONTRAR(".",A1,1)+1)-ENCONTRAR(".",A1,1)-1),"000") & "." & TEXTO(EXTRAE(A1,ENCONTRAR(".",A1,ENCONTRAR(".",A1,1)+1)+1,ENCONTRAR(".",A1, ENCONTRAR(".",A1,ENCONTRAR(".",A1,1)+1)+1)-ENCONTRAR(".",A1,ENCONTRAR(".",A1,1)+1)-1), "000") & "." & TEXTO(DERECHA(A1,LARGO(A1)-ENCONTRAR(".",A1,ENCONTRAR(".",A1,ENCONTRAR( ".",A1,1)+1)+1)),"000")
This comment was minimized by the moderator on the site
Thanks for your help on translating the formula.
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations