如何在Excel中快速将IP地址从低到高排序?
通常,我们在Excel中使用Sort函数对字符串进行排序。 但是,如果需要一些IP地址进行排序,则直接使用“排序”功能可能会导致排序顺序错误,如下面的屏幕截图所示。 现在,我有一些方法可以在Excel中快速正确地对IP地址进行排序。
排序功能排序错误
正确排序
按公式对IP地址进行排序
按VBA排序IP地址
按文本到列对IP地址排序
按公式对IP地址进行排序
使用公式填充IP地址,然后排序。
1.选择一个与IP地址相邻的单元格,然后键入此公式
=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")
express 输入
键,然后将填充手柄拖动到单元格上以应用此公式。
2.复制公式结果并将其作为值粘贴在下一列中。 看截图:
3.保持粘贴值处于选中状态,然后单击 Data > 将A到Z排序
.
4.在 排序警告 对话,保持 扩大选择
检查。
5。 单击 排序
。 现在,IP地址已从低到高排序。
您可以删除帮助器列。
按VBA排序IP地址
这是一个VBA代码,也可以为您提供帮助。
1。 按 Alt + F11键 启用 Microsoft Visual Basic应用程序 窗口。
2。 点击 插页 > 模块,将代码复制并粘贴到空白脚本中。
VBA:填写IP地址
Sub FormatIP()
UpdatbyExtend
office20171215
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
3. Then click Tools > Reference, and check Microsoft VBScript Regular Expressions 5.5 in the popping dialog.
4. Click OK and press F5 key, a dialog pops out to remind you to select a range to work.
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:
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.
3. The select all cells containing the IP addresses and the split cells, and click Data > Sort.
4. In the Sort dialog, clicking Add level to sort data from column B to E (the split cells). See screenshot:
5. Click OK. Now the columns have been sorted.
Best Office Productivity Tools
Transform Hours into Minutes with Kutools for Excel!
Ready to supercharge your Excel tasks? Harness the power of Kutools for Excel - your ultimate time-saving tool. Streamline intricate tasks and glide through your data like a pro. Experience Excel at lightning speed!
Why You Need Kutools for Excel
🛠️ Over 300 Powerful Features: Kutools is packed with more than 300 advanced features, simplifying your work in over 1500 scenarios.
📈 Superior Data Processing: Merge cells, remove duplicates, and perform advanced data conversions – all without breaking a sweat!
⏱️ Efficient Batch Operations: Why put in extra effort when you can work smart? Import, export, combine, and tweak data in bulk with ease.
📊 Customizable Charts and Reports: Access a broad variety of additional charts and generate insightful reports that tell a story.
🗄️ Powerful Navigation Pane: Gain an advantage with the robust Column Manager, Worksheet Manager, and Custom Favorites.
📝 Seven Types of Drop-down Lists: Make data entry a breeze with drop-down lists of various features and types.
🎓 User-Friendly: A breeze for beginners and a powerful tool for experts.
Download Now and Soar Through Time with Excel!
Read More... Free Download... Purchase...
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!
Read More... Free Download... Purchase...