How to search in selected area in Numbers

While searching in Numbers, I would like a search in selected area only and not in all the sheets in a file

It searches indiscriminately. This is a problem. I cannot narrow down my search.




MacBook Air (M3, 2024)

Posted on Dec 1, 2024 2:10 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 9, 2024 7:59 AM

I use a regular internet search, not the useless "search" feature of this forum, to find posts here.


If you are saying that when you type a number into the "find" field of the script it tacks a 0 onto the end as you are typing, I have not seen that and have no explanation why it would. It is a text entry field. It does not check if something is a digit or any other character or if the entire string when done is a number or just text. Same with the "replace" entry field.


I have found where the problem is with numbers in cells. When getting the value of a cell, an integral number like 123 is received as 123.0 in the script. The script below uses the formatted value of the cell (i.e., what you see displayed) instead. Note that it will round numbers to the number of decimals currently displayed. The built-in find/replace appears to do the same thing.


I made it so it only changes cells that actually need a change. If nothing in a cell was found/replaced then it leaves it alone. So that rounding stuff I mentioned above will only occur to cells that had something found/replaced.


It ignores cells with formulas and those that are blank. The older version of SGIII's script was this way. I just put that back into it.


It highlights "Next" as the default button in the "find" dialog.


It no longer considers case. ABC is the same as Abc, aBc, and so on.


Copy the script from below and replace the one in the shortcut with it. Let me know if it does all you need it to do.



-- Numbers App Find&Replace in Selection
-- SGIII Author
-- 12/09/2024 Badunit edit 
-- 1) Reincorporate the check for formulas and missing values so those cells are not affected. 
-- 2) Use the formatted value of the cell for the find/replace. Prior to this, integral numbers such 
--  as 123 were being turned into 123.0. Note that this will round any decimal numbers to the number of
--  places being displayed, just as the built-in find/replace does.
-- 3) Reincorporated "next" as default button for the "find" dialog
-- 4) Changed it to ignore case vs consider case
-- 5) Set new values for cells only if they have changed.

set f to display dialog "Find this in selected cells in Numbers " default answer "" with title "Find and Replace Step 1" buttons {"Cancel", "Next"} default button "Next"
set f to text returned of result
if f = "" then display dialog "Did you really mean you want to replace null with something?  This will result in your replacement string being inserted between each pair of letters." buttons {"Cancel", "Yes"} with title "Find and Replace"

display dialog "Replace '" & f & "' with " default answer "" with title "Find and Replace Step 2"
set r to text returned of result

try
	tell application "Numbers" to tell front document to tell active sheet
		tell (first table whose selection range's class is range)
			set sr to selection range
			tell sr to repeat with i from 1 to count cells
				--if not a formula and not blank
				if cell i's formula is missing value and cell i's value is not missing value then
					set oVal to (cell i's formatted value)
					--return oVal
					set nVal to my findReplace(oVal, f, r)
					-- return nVal
					if (cell i's formatted value) ≠ nVal then
						set cell i's value to nVal
					end if
				end if
			end repeat
		end tell
	end tell
on error
	display dialog "Are the cells where you want to do a Find Replace selected?" buttons {"cancel"} with title "Oops!"
end try

--handlers
to findReplace(tt, f, r)
	set oTID to AppleScript's text item delimiters
	ignoring case
		set AppleScript's text item delimiters to f
		set lst to tt's text items
		set AppleScript's text item delimiters to r
		set tt to lst as string
	end ignoring
	set AppleScript's text item delimiters to oTID
	return tt
end findReplace

18 replies

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 to search in selected area in Numbers

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