Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a random row picker that selects a row

I have a Google Spreadsheets containing about 50 rows, each of which has values in the first four cells of the row. I'd like to build something where I can click a button (or a cell?) and have it return one of these rows, selected randomly. I had assumed that this would be fairly simple in Google Sheets, but lots of searching online hasn't yielded anything useful.

I'm open to building something different (simple web app?) that will still do what I'm looking for.

Does anyone know how to do this, or even know some different language that I should be using as search terms?

like image 506
radionowhere Avatar asked Dec 19 '22 00:12

radionowhere


2 Answers

If you insert a new ColumnA and populate it with:

=randbetween(1,100)  

you might then use a formula like:

=query(Sheet1!A1:E50,"select B,C,D,E order by A limit 1")  

and even have this update itself every minute or hour by selecting Recalculation in Spreadsheet settings..., otherwise on command with Ctrl+R.

HOWEVER, the result is effectively provisional until the sheet has saved.

like image 177
pnuts Avatar answered Jan 13 '23 12:01

pnuts


You can use Google Apps Script, which will allow you to add the functionality you require into your spreadsheet. It uses JavaScript and the link I have given above will lead to some easy to follow examples. If you get stuck, then the Web Applications Stack Exchange site has many Q & A's on scripting Google's web apps.

If you reach the limits of Google Apps Script at some point, you may write your own application which interacts with your Google Sheet via their API. The APIs support multiple scripting and programming languages and searching Github will yield many open source libraries helpful for using Google Sheets and other Google Apps.

like image 24
ljs.dev Avatar answered Jan 13 '23 10:01

ljs.dev