My expected result is very simple – I have used data validation to place a list of column titles in a cell. When a user selects a column title and clicks the button, I want them to be taken to the COLUMN where that word is the title.
For example, user selects "Game 5", which is in column 34. They click "JUMP" and are taken to Column 34 Row 1.
Likewise, user selects "Game 52", which is in column 76. User clicks "JUMP" button and is taken to Column 76 Row 1.
Here's what I have so far:
MATCH function set up in Cell AP1, searching for the dropdown value location within the top row. This basically returns the Column # that I want the jump button to move to.
Then, I have my script:
function jump2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("ClassicGames"); // change to sheet containing dates
var r = s.getRange("AP1").getValue(); //change A1 to cell containing =match formula
s.setActiveSelection(s.getRange(r));
}
I thought maybe this combination would just take me to whatever number the MATCH function finds. For instance, if r = 35, the user will move to the 35th column.
Best Answer
You want a user to select a column letter from a dropdown list, and then have the spreadsheet "jump" to that column. There may be several ways to solve your question. Consider this answer as one approach.
There are several elements required to achieve your goal:
To Do
1 - paste the following scripts into your project.
2 - create a sheet called "ColumnList". This will be the source for the dropdown options.
3 - Run the script
buildlist
. You can run this whenever you like; I chose not to include it inonOpen
because it might not execute before the user has chosen from dropdown.4 - On sheet = "ClassicGames, create a dropdown in Cell "A2". From the menu: Data > Data Validation > Criteria=List from a Range > Select a Data Range="ColumnList!A1:A1000", Save. By specifying a long range, and new columns that are added to the list will automatically be added to the dropdown options.
The
onEdit
script uses Event Objects to capture the range, value , and the sheet selected. Anif
-based logic statement makes sure that the script only runs if the edited cells is "A2" and the edited sheet = "ClassicGames".Two utility scripts,
columnToLetter
andletterToColumn
, are used to convert column numbers to letters and vice versa.