Imagine you have a worksheet filled with a list of alphanumeric strings, and your goal is to transform each alphanumeric value in these strings into MAC addresses by inserting colons, as illustrated in the following screenshot. How can you efficiently achieve this? This tutorial provides straightforward methods to help you tackle this challenge.
=LEFT(A2,2)&":"&MID(A2,3,2)&":"&MID(A2,5,2)&":"&MID(A2,7,2)&":"&MID(A2,9,2)&":"&RIGHT(A2,2)
Note: In the formula, A2 is the first cell in the list of strings to be formatted as mac format.
The formula provided in the method above does not look very easy to grasp. If you are looking for a simpler solution, then the Add Text utility of Kutoos for Excel is highly recommended. Using this utility, you can easily add colons to cells at specified positions to quickly format the steing in those cells as mac addresses. Please follow the steos below.
After downloading and installing Kutools for Excel, go to the Kutools tab, select Text > Add Text to open the Add Text dialog box, and then configure as follow.
Tip: In this case, I need to add a colon after every two numbers in cells, so I enter 2, 4, 6, 8 and 10 separated by commas. See screenshot:
Result
Strings in the selected cells are now formatted as mac address as shown in the screenshot below.
Notes:You also can apply VBA code to format number and text as mac address in Excel. Please do as follows.
Sub FormatMAC() 'Updated by Extendoffice 20231103 Dim I As Long Dim xRg As Range Dim xCell As Range Dim xVal As String Dim xStr As String On Error Resume Next Set xRg = Application.InputBox("Please select range:", "Kutools for Excel", Selection.Address, , , , , 8) If xRg Is Nothing Then Exit Sub On Error GoTo 0 For Each xCell In xRg xVal = xCell.Value If InStr(xVal, ":") > 0 Then xVal = Replace(xVal, ":", "") End If For I = 1 To Int(Len(xVal) / 2) xStr = xStr & Mid(xVal, 2 * I - 1, 2) & ":" Next xCell.Value = Left(xStr, Len(xStr) - 1) 'Remove the last ":" xStr = "" Next End Sub
Then you can see the selected cells are formatted as mac address as shown in the screenshot below.