Applying the clear command to a cell will restore the cell to its pristine condition, devoid of styling or format.
clearv : Clear the contents of a specified range of cells, including formatting and style.
clearrange
While useful in specific situations, the clear command is not the same as resetting a cell to a default value. Use the following example script to reset all of the currently selected cells to their default values, while retaining their individual styling and format parameters:
Reset Selected Cells to Default Values
01
propertydefaultStepperValue : 1
02
propertydefaultSliderValue : 1
03
propertydefaultCheckboxValue : false
04
propertydefaultCurrencyValue : 0
05
propertydefaultNumberValue : 0
06
propertydefaultTextValue : ""
07
propertydefaultDateAndTime : missing value
08
09
tellapplication "Numbers"
10
activate
11
try
12
if not (existsdocument 1) then errornumber 1000
13
telldocument 1
14
try
15
tellactive sheet
16
set theselectedTableto ¬
17
(the firsttablewhoseclassofselection rangeisrange)
18
end tell
19
on error
20
errornumber 1001
21
end try
22
setdefaultDateAndTimeto (current date)
23
tellselectedTable
24
set thecellCountto thecountofcellsof theselection range
25
repeat withifrom 1 to thecellCount
26
tellcelliof theselection range
27
ifformatis in {stepper} then
28
set thevaluetodefaultStepperValue
29
else ifformatis in {slider} then
30
set thevaluetodefaultSliderValue
31
else ifformatis in {checkbox} then
32
set thevaluetodefaultCheckboxValue
33
else ifformatis in {currency} then
34
set thevaluetodefaultCurrencyValue
35
else ifformatis in {date and time} then
36
set thevaluetodefaultDateAndTime
37
else ifformatis in {number} then
38
set thevaluetodefaultNumberValue
39
else ifformatis in {text} then
40
set thevaluetodefaultTextValue
41
else
42
try
43
set thevalueto ""
44
end try
45
end if
46
end tell
47
end repeat
48
end tell
49
end tell
50
on errorerrorMessagenumbererrorNumber
51
iferrorNumberis 1000 then
52
setalertStringto "MISSING RESOURCE"
53
seterrorMessageto ¬
54
"Please create or open a document before running this script."
55
else iferrorNumberis 1001 then
56
setalertStringto "SELECTION ERROR"
57
seterrorMessageto ¬
58
"Please select a table before running this script."
Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. MACOSXAUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. MACOSXAUTOMATION.COM provides this only as a convenience to our users. MACOSXAUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and MACOSXAUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from MACOSXAUTOMATION.COM and that MACOSXAUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.