How do I format a cell for a MAC Address, an IP Address or a Part Number?

I am putting together a Network Table containing the details of all of my Network Devices and Connections. I need this because every time I need service, the first thing they ask me is the Model Number and Serial Number of my Modem, which is buried deep inside of a Wall Closet; or, they ask me for an IP or MAC Address which I cannot possibly memorize. So, I need to mix Number Formats with Text Formats for the following Example Cell items:

1. MAC Address: 00:1R:54:C8:CD:30
2. IP Address: 250.250.250.58
3. Part Number: 515291-017-00

Is there a way to mix these formats, as shown above? I cannot find it anywhere. From what I can find, Numbers only allows Text OR Number Formats, but no mixing of the two formats. Please help!

Thank you!

Various Macs, Mac OS X (10.5.6), Numbers '09, Version 2.0.1 (316)

Posted on Apr 26, 2009 12:19 PM

Reply
15 replies

Apr 26, 2009 9:10 PM in response to yosappy

Hi yo',

The three examples can each be easily handled in a cell formatted to Text, and a cell left on "Automatic" will automatically show them as Text.

There's nothing particularly numeric about any of these, despite the fact that each uses numeric characters.

Functionally, they're simply labels, used in indexing, but not used in any calculations.

The only instances in which I can see Automatic formatting failing are in the cases of serial numbers and the like containing either no non-numeric characters or containing only the letter E. Numbers will see these as "numbers" and will format them as such. Short ones will be aligned right, rather than left like the three examples. Long ones (over 11 digits) will be rounded and displayed in scientific notation. Those containing an E will be interpreted as being written in scientific notation and displayed as such.

In these cases, you can force Numbers to see the entry as Text by starting the entry with a single quote.

Example: 123456789098765 displays as 1.23457E+14 (scientific notation)
'123456789098765 displays as 123456789098765

Regards,
Barry

Apr 27, 2009 11:24 AM in response to Barry

Barry,

Yes, I agree with, and understand, what you have written. Now that I have 2 answers, I realize that I did not properly ask my question. I know that I can just Format the Cell as Text and then I can basically put anything in that Cell; but, then I have to type EVERY CHARACTER for each Cell. Thank you for the single quote recommendation as I did not know about that one, and I already had the problem with a long serial number displaying in Scientific Notation, which does not help me at all.

What I really want to do is to be able to just type the numbers and characters, and have the Cell automatically Format it as an IP Address, a MAC Address or a Part Number. Like how you can format the Cell as a Telephone Number and it automatically puts in the spaces, parentheses and hyphens for you. That is what I really want, the Application making it easier for me to enter the data without having to type each identical character, like a period, a space or a colon, for each entry. Does that state my issue a little better?

Thank you,

Yo

Apr 27, 2009 12:17 PM in response to Brie Fly

The difficult part of all this is if the OP wants that cell to automatically and robustly determine which format it is. I have no idea how it can know whether the number being entered is a MAC address, IP address, or part number. There doesn't seem to be anything that makes each stand out if the dots and dashes are not typed in. In the telephone number example, the software knows it is a telephone number so it knows where to put the dashes. That's not the case here. For example is 25025025058 an IP address (250.250.250.58) or a part number (250250-250-58)? Is 250250250158 an IP address (250.250.250.158) or a MAC address (25:02:50:25:01:58)?

My suggestion is to have three columns. One is IP address, one is MAC address, one is serial number. Format each so they add the dashes, colons, and dots where desired. Type the numbers/letters into the correct column.

Message was edited by: Badunit

Apr 27, 2009 12:48 PM in response to Badunit

Badunit,

Yes, I already have each type of number in a separate column. That is the easy part. I wasn't trying to make this thing a genius, yet. Although, maybe someday it can be that smart..............What I can't do is your second last sentence, "Format each so they add the dashes, colons, and dots where desired." HOW DO I ADD THE DESIRED, REPEATED CHARACTERS WHERE I WANT THEM, without having to constantly type them for each entry?

Thank you,

Yo

Apr 27, 2009 1:29 PM in response to yosappy

No need to yell. It wasn't clear what you were asking. Sounded like one cell, three formats to me.

I'm not so sure you'll be able to do a custom format for the MAC address where you type in the numbers and letters and it reformats it (i.e, adds the colons) in the same cell after you hit return. Custom format doesn't seem to handle that unless it is all digits.

You might have the same problem with the part numbers if they have any letters in them or if different parts have different formats. If all numbers and the format is always the same, a custom format is possible.

IP address custom format is ###.###.###.### and hide the separator. You have to type in three digits for each section, such as "058" not "58".

Part Number, if it is all numbers and always of the format you gave is ######-###-## and hide the separator.

Apr 27, 2009 2:25 PM in response to Badunit

The OP shout so loud that I was unable to sleep.

Here are three simple scripts to do the tricks.

(script 1)

--[SCRIPT entryToMACaddress]

(*
Save the script as a Script, an Application or an Application Bundle: entryToMACaddress.xxx
Move the newly created application into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
select a range of entries which are supposed to be IP addresses
menu Scripts > Numbers > entryToMACaddress
the script will insert the required dash chars.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
+++++++
Yvan KOENIG (Vallauris, FRANCE)
27 avril 2009
*)
on run

set {rname, tName, sName, dName, colNum1, rowNum1, colNum2, rowNum2} to my getSelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName

repeat with r from rowNum1 to rowNum2
tell row r
repeat with C from colNum1 to colNum2
set txt to (value of cell C) as text
if (count of txt) < 13 then
set txt to text -12 thru -1 of ("000000000000" & txt)
set ipa to text 1 thru 2 of txt & ":" & text 3 thru 4 of txt & ":" & text 5 thru 6 of txt & ":" & text 7 thru 8 of txt & ":" & text 9 thru 10 of txt & ":" & text 11 thru 12 of txt
set value of cell C to ipa
end if
end repeat
end tell
end repeat
end tell
end run
--=====
on getSelParams()
local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
if my parleAnglais() then
if r_Name is missing value then error "No sheet has a selected table."
else
if r_Name is missing value then error "Aucune feuille ne contient une table sélectionnée."
end if

set two_Names to my decoupe(r_Name, ":")
tell application "Numbers" to tell document d_Name to tell sheet s_Name to tell table t_Name
set col_Num1 to address of column of cell (item 1 of two_Names)
set row_Num1 to address of row of cell (item 1 of two_Names)
if item 2 of two_Names = item 1 of two_Names then
set {col_Num2, row_Num2} to {col_Num1, row_Num1}
else
set col_Num2 to address of column of cell (item 2 of two_Names)
set row_Num2 to address of row of cell (item 2 of two_Names)
end if
end tell -- _Numbers …
return {r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2}
end getSelParams
--=====
(*
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
*)
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum

tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theRange, theTable, theSheet, theDoc}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]


(script 2)

--[SCRIPT entryToIPaddress]

(*
Save the script as a Script, an Application or an Application Bundle: entryToIPaddress.xxx
Move the newly created application into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
select a range of entries which are supposed to be IP addresses
menu Scripts > Numbers > entryToIPaddress
the script will insert the required period chars.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
+++++++
Yvan KOENIG (Vallauris, FRANCE)
27 avril 2009
*)
on run

set {rname, tName, sName, dName, colNum1, rowNum1, colNum2, rowNum2} to my getSelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName

repeat with r from rowNum1 to rowNum2
tell row r
repeat with C from colNum1 to colNum2
set txt to (value of cell C) as text
if (count of txt) is 16 then
set ipa to character 1 of txt & text 3 thru 4 of txt & "." & text 5 thru 7 of txt & "." & text 8 thru 10 of txt & "." & text 11 thru 12 of txt
set value of cell C to ipa
end if
end repeat
end tell
end repeat
end tell
end run
--=====
on getSelParams()
local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
if my parleAnglais() then
if r_Name is missing value then error "No sheet has a selected table."
else
if r_Name is missing value then error "Aucune feuille ne contient une table sélectionnée."
end if

set two_Names to my decoupe(r_Name, ":")
tell application "Numbers" to tell document d_Name to tell sheet s_Name to tell table t_Name
set col_Num1 to address of column of cell (item 1 of two_Names)
set row_Num1 to address of row of cell (item 1 of two_Names)
if item 2 of two_Names = item 1 of two_Names then
set {col_Num2, row_Num2} to {col_Num1, row_Num1}
else
set col_Num2 to address of column of cell (item 2 of two_Names)
set row_Num2 to address of row of cell (item 2 of two_Names)
end if
end tell -- _Numbers …
return {r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2}
end getSelParams
--=====
(*
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
*)
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum

tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theRange, theTable, theSheet, theDoc}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]


(script 3)

--[SCRIPT entryToPartNumber]

(*
Save the script as a Script, an Application or an Application Bundle: entryToPartNumber.xxx
Move the newly created application into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
select a range of entries which are supposed to be IP addresses
menu Scripts > Numbers > entryToPartNumber
the script will insert the required dash chars.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
+++++++
Yvan KOENIG (Vallauris, FRANCE)
27 avril 2009
*)
on run

set {rname, tName, sName, dName, colNum1, rowNum1, colNum2, rowNum2} to my getSelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName

repeat with r from rowNum1 to rowNum2
tell row r
repeat with C from colNum1 to colNum2
set txt to (value of cell C) as text
if (count of txt) is 16 then
set ipa to character 1 of txt & text 3 thru 7 of txt & "-" & text 8 thru 10 of txt & "-" & text 11 thru 12 of txt
set value of cell C to ipa
end if
end repeat
end tell
end repeat
end tell
end run
--=====
on getSelParams()
local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
if my parleAnglais() then
if r_Name is missing value then error "No sheet has a selected table."
else
if r_Name is missing value then error "Aucune feuille ne contient une table sélectionnée."
end if

set two_Names to my decoupe(r_Name, ":")
tell application "Numbers" to tell document d_Name to tell sheet s_Name to tell table t_Name
set col_Num1 to address of column of cell (item 1 of two_Names)
set row_Num1 to address of row of cell (item 1 of two_Names)
if item 2 of two_Names = item 1 of two_Names then
set {col_Num2, row_Num2} to {col_Num1, row_Num1}
else
set col_Num2 to address of column of cell (item 2 of two_Names)
set row_Num2 to address of row of cell (item 2 of two_Names)
end if
end tell -- _Numbers …
return {r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2}
end getSelParams
--=====
(*
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
*)
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum

tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theRange, theTable, theSheet, theDoc}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]


Yvan KOENIG (from FRANCE lundi 27 avril 2009 23:25:02)

Apr 27, 2009 3:11 PM in response to Badunit

My suggestion is to have three columns.


That's what I had assumed was the plan. Then formatting an additional cell column corresponding to each data cell could be easily populated with

=MID(A2,1,3)&"."&MID(A2,4,3)&"."&MID(A2,7,3)&"."&MID(A2,10,3)

to create a URL, for example.

(Note, the example doesn't employ any "smarts", so it assumes the input string was 12 digits in a cell (preceded by a single quote to flag the cell as "text") -- it assumes leading zeroes, if any, are included. The "output" cell is formatted as "automatic". Input of '250250250250 would be output as 250.250.250.250 -- the leading single quote flags the cell as text and is ignored by the parsing.)

Apr 29, 2009 12:27 AM in response to Brie Fly

If going the formula route, then I'd like to add a few suggestions. Maybe you or someone with a similar issue will be able to pick out a piece and apply to your situation.

Assuming part# is always 11 digits and MAC always contains at least one non-number, then the input would be distinguishable. First, format your entry cells as Text (e.g. column A) so the leading zeros remain as you type them. Then, in column B:

=IF(LEN(A1)=11,"Format PART",IF(ISERROR(VALUE(A1)),"Format MAC","Format IP"))

This uses the fact that VALUE will return an error if the cell doesn't contain a number. In formula above, you'd want to replace Format PART, MAC, and IP with your formatting formulas.

So, with Brie Fly's IP format formula:
=IF(LEN(A1)=11,"PART",IF(ISERROR(VALUE(A1)),"MAC",MID(A1,1,3)&"."&MID(A1,4,3)&". "&MID(A1,7,3)&"."&MID(A1,10,3)))

If MAC does not always contain at least one non-number, then you'll need to tag the MAC entry to be able to distinguish from IP and strip it out later while formatting.

For example: for MAC you might type #001154181130

Then the formula would look like:
=IF(LEN(A1)=11,"Format PART",IF(ISERROR(VALUE(A1)), IF(LEFT(A1)="#","Format MAC-strip #", "Format MAC"),"Format IP"))

Or, you could simplify the formula by ALWAYS tagging MAC entries, so type #001r54c8cd30

Then formula might be:
=IF(LEN(A1)=11,"Format PART",IF(LEN(A1)=12,"Format IP", IF(LEN(A1)=13,"Format MAC-strip #","must be typo, wrong number digits"))

Also, if you didn't want to worry about capitalizing letters when typing, you could use UPPER in the formatting portion of the formula for MAC.

Robin

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do I format a cell for a MAC Address, an IP Address or a Part Number?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.