Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Numbers

Can I automatically populate. a cell in a spreadsheet from a cell in another spreadsheet?


Posted on Apr 3, 2021 4:12 AM

Reply
Question marked as Best reply

Posted on Apr 3, 2021 7:34 AM

Yes. Scripts can be fiddly. But so can formulas.


Here's a basic AppleScript to get you started if you really need to do this. Fill in particulars of your set up in first lines.


property src1 : {doc:"Source1.numbers", sht:"Sheet 1", tbl:"Table 1", rng:"A2:B4"}
property tgt1 : {doc:"Target.numbers", sht:"Sheet 1", tbl:"Consolidated", rng:"A2:B4"}

property src2 : {doc:"Source2.numbers", sht:"Sheet 1", tbl:"Table 1", rng:"A2:B4"}
property tgt2 : {doc:"Target.numbers", sht:"Sheet 1", tbl:"Consolidated", rng:"A5:B7"}


copyVals(src1, tgt1)
copyVals(src2, tgt2)

to copyVals(src, tgt)
	tell application "Numbers"
		try
			--read values in source range into AppleScript list
			tell document (src's doc)
				tell sheet (src's sht)
					tell table (src's tbl)
						tell range (src's rng)
							set vv to cells's value
						end tell
					end tell
				end tell
			end tell
			
			--write values from list to target range
			tell document (tgt's doc)
				tell sheet (tgt's sht)
					tell table (tgt's tbl)
						tell range (tgt's rng)
							repeat with i from 1 to count cells
								set cell i's value to vv's item i
							end repeat
						end tell
					end tell
				end tell
			end tell
		on error
			display alert "Check addresses, ranges, and size of destination table" buttons "Ok"
		end try
		
	end tell
end copyVals


SG

6 replies
Question marked as Best reply

Apr 3, 2021 7:34 AM in response to drtwoones

Yes. Scripts can be fiddly. But so can formulas.


Here's a basic AppleScript to get you started if you really need to do this. Fill in particulars of your set up in first lines.


property src1 : {doc:"Source1.numbers", sht:"Sheet 1", tbl:"Table 1", rng:"A2:B4"}
property tgt1 : {doc:"Target.numbers", sht:"Sheet 1", tbl:"Consolidated", rng:"A2:B4"}

property src2 : {doc:"Source2.numbers", sht:"Sheet 1", tbl:"Table 1", rng:"A2:B4"}
property tgt2 : {doc:"Target.numbers", sht:"Sheet 1", tbl:"Consolidated", rng:"A5:B7"}


copyVals(src1, tgt1)
copyVals(src2, tgt2)

to copyVals(src, tgt)
	tell application "Numbers"
		try
			--read values in source range into AppleScript list
			tell document (src's doc)
				tell sheet (src's sht)
					tell table (src's tbl)
						tell range (src's rng)
							set vv to cells's value
						end tell
					end tell
				end tell
			end tell
			
			--write values from list to target range
			tell document (tgt's doc)
				tell sheet (tgt's sht)
					tell table (tgt's tbl)
						tell range (tgt's rng)
							repeat with i from 1 to count cells
								set cell i's value to vv's item i
							end repeat
						end tell
					end tell
				end tell
			end tell
		on error
			display alert "Check addresses, ranges, and size of destination table" buttons "Ok"
		end try
		
	end tell
end copyVals


SG

Numbers

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