Custom Format MAC address

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
Hi All, I'm working on a document which requires a user to enter the MAC address of a computer. The current document requires they put these 6 values in separate cells. For formatting purposes, I'd like it to be in one cell only. Further, I'd like them to be able to just enter the characters, not the separator. I was trying to work this out in Custom Formatting, but wasn't able to. The what should appear should be TT-TT-TT-TT-TT-TT, where TT is two text characters. Thanks in advance.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Custom formatting won't work for that (the separator is usually a colon rather than hyphen is it not?) so you would need to use code to add the separator - would that be acceptable?
 
Upvote 0
Thanks for your reply. Actually, you're right, the separator should be a colon. Can you help out? Thanks in advance.
 
Upvote 0
Right-click the worksheet tab, choose View Code and paste this in:
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngCell As Range
    Dim n As Long
    Dim strTemp As String
    Const csMONITOR_RANGE As String = "A1:A100"
    
    On Error GoTo clean_up
    
    If Not Intersect(Target, Range(csMONITOR_RANGE)) Is Nothing Then
        Application.EnableEvents = False
        For Each rngCell In Intersect(Target, Range(csMONITOR_RANGE)).Cells
            If Len(rngCell.Value) = 12 Then
                For n = 1 To 12 Step 2
                    strTemp = strTemp & ":" & Mid$(rngCell.Value, n, 2)
                Next n
                rngCell.Value = Mid$(strTemp, 2)
            End If
        Next rngCell
    End If
    
clean_up:
    Application.EnableEvents = True

End Sub

adjust the red part to match whatever range you need to monitor for input.
 
Upvote 0
Thanks for your help. However, I guess I didn't explain what I want precisely enough. I am not looking to transform 6 individual cells into one cell with a colon separating their values, I'm interested in having a person simply enter 12 characters into a single cell and when they exit, it is formatted so that between every two values there appears a colon.
 
Upvote 0
That's exactly what the code does. I assumed you wanted it to work for a 12 digit entry in a number of cells, but if not, just change the red part to one cell address.
 
Upvote 0
Fantastic, it works just fine. Thanks a lot!
 
Upvote 0

Forum statistics

Threads
1,214,846
Messages
6,121,905
Members
449,054
Latest member
luca142

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