Custom number format for displaying MAC addresses?

skiraly017

New Member
Joined
Oct 18, 2005
Messages
6
I'm trying to create an Excel sheet to display MAC addresses in the following format -

00:00:00:00:00:00

However. the characters can be either letters or numbers. I've modified the "hh:mm:ss" template to accomodate the format I need, but it will not recognize letters for the obvious reason. Is there a wildcard character that I could use in this format or has anyone created a format that would meet my needs? If I can pull this off, it could mean a promotion. Thanks in advance for any and all help.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
If a column could be inserted, this formula may work:

=MID(A1,1,2)&":"&MID(A1,3,2)&":"&MID(A1,5,2)&":"&MID(A1,7,2)&":"&MID(A1,9,2)&":"&MID(A1,11,2)

This formats the value in cell A1 which is: ae12e034bb00 to ae:12:e0:34:bb:00
 
Upvote 0
If you can't use an extra column, a VBA solution like this might work for you:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myText As String

    If Len(Target) <> 12 Then Exit Sub  'check for correct length
    If Target.Column <> 1 Then Exit Sub 'only Column A
    Application.EnableEvents = False

    myText = Left(Target.Text, 2) _
        & ":" & Mid(Target.Text, 3, 2) _
        & ":" & Mid(Target.Text, 3, 2) _
        & ":" & Mid(Target.Text, 3, 2) _
        & ":" & Mid(Target.Text, 3, 2) _
        & ":" & Right(Target.Text, 2)
    Target.Value = myText               'put MAC string back into original cell

    Application.EnableEvents = True
End Sub

  • How to use the above code:

    Press Alt-F11 to open the VBE.
    Press Control-R to open the Project Explorer.
    Click "Microsoft Excel Objects" for the file you're working on.
    Double-click the sheet module where you need this to work.

    Open the Code pane with F7.
    Paste the above code in.
    Press Alt-Q to close the VBE and return to Excel

Hope that helps!
 
Upvote 0
Thanks for the help...

...but I couldn't get either of those methods to work. Maybe I'm trying to do something that can't be done.
 
Upvote 0
How did you try the various suggestions?

Could you post some sample data?

You've indicated the result you want but not shown us the raw data.
 
Upvote 0
The results.

I followed the VBA idea instructions to the letter, but when I entered the "unformatted" MAC address and hit enter, it stayed unformatted.

The formula generated a looping(?) error once and then form that point on just placed itself as the test in whatever cell I tried to apply it to.
 
Upvote 0
Where did you enter the value to be formatted?
 
Upvote 0
Assumming your addresses are in column A, starting in row 2

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 1 Then Exit Sub 'column of interest
If Target.Row < 2 Then Exit Sub 'lowest row
If Target.Cells.Count > 1 Then Exit Sub 'no multiple selections
With Target
'ex: ae:12:e0:34:bb:00
Application.EnableEvents = False
.Value = Left(.Value, 2) & ":" & Mid(.Value, 3, 2) & ":" & Mid(.Value, 5,2) & ":" & Mid(.Value,7,2)& ":" & Right(.Value,2)
Application.EnableEvents = True
End With
End Sub

This goes in the WorkSheet module

HTH

lenze
 
Upvote 0
Lenze hit the nail on the head.

I had to modify the script because it was only allowing five octets and dropping the sixth.

How would I modify the script so that the format would apply to all columns, not just "A"?

TIA.
 
Upvote 0

Forum statistics

Threads
1,217,415
Messages
6,136,506
Members
450,017
Latest member
Alvi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top