Forum Discussion
Table Entry Line
So I have suggested that excel add an 'ENTRY LINE' to tables. See that suggestion here:
https://feedbackportal.microsoft.com/feedback/idea/ae0a8991-71fa-ed11-a81c-000d3ae5b6f4
I image it would look something like this (EDIT: updated image):
So you can enter data at the top and hit enter and it would be added to the table without scrolling to the bottom.
Well, in the mean time, I made the script and that button is fully functional and because it is a script it will work Both online and in the app. See attached file.
Please let me know you LIKE it with a thumbs up or better yet leave a comment to let me know if you tried it out. Also welcoming feedback and improvements. I'm already considering to expand this to cycle through all tables on the sheet. Here is the present script (updated script):
/**
* This script inserts the row above a table into the table.
*/
function main(workbook: ExcelScript.Workbook) {
let wksht = workbook.getActiveWorksheet();
//Unlock worksheet
let wkshtProtect = wksht.getProtection().getProtected();
if (wkshtProtect) {wksht.getProtection().unprotect(); };
//find active cell and 3x3 around that cell as 'activeBubble' to find correct table
let activeCell = workbook.getActiveCell();
let aMinRow = activeCell.getRowIndex() - 1;
if (aMinRow < 0) { aMinRow = 0; };
let aMinCol = activeCell.getColumnIndex() - 1;
if (aMinCol < 0) { aMinCol = 0; };
let activeBubble = wksht.getRangeByIndexes(aMinRow, aMinCol, 3, 3).getAddress();
//Check each table if row above overlaps activeBubble
let tCount = wksht.getTables().length;
let foundTable = 0;
// let tbl = wksht.getTables().shift()
wksht.getTables().forEach( (tbl) => {
foundTable= Math.abs(foundTable);
let newData = tbl.getHeaderRowRange().getOffsetRange(-1, 0);
if (wksht.getRange(newData.getAddress()).getIntersection(activeBubble)) {
//let remFormat = newData.getFormat();
//tbl.addRows(-1, newData.getValues());
tbl.addRow();
let newRow = tbl.getRange().getLastRow(); //.getTotalRowRange().getLastRow();
let n = newData.getColumnCount();
for (let i = 0; i< n; i++) {
//selectively inserts data from input line (i.e. do not overwrite table formulas)
if ( !newRow.getCell(0, i).getFormula().toString().startsWith("=") ) {
newRow.getCell(0, i).copyFrom(newData.getCell(0, i), ExcelScript.RangeCopyType.values);
};
//selectively clear input line (i.e. do not clear formulas)
if ( !newData.getCell(0, i).getFormula().toString().startsWith("=") ) {
newData.getCell(0, i).setValue(""); //.clear
};
};
//put cursor back on 'start' of input line
newData.getCell(0,0).select();
} else {foundTable++};
});
//console.log("tCount=" + tCount + " foundTable=" + foundTable);
if (tCount == foundTable){
//console.log("no table found next to last active cell.");
//return;
throw 'no table found next to last active cell';
}
//TEST CODE SECTION - IGNORE
//if it was protected, re-protect
if (wkshtProtect) {wksht.getProtection().protect();};
}
10 Replies
- SergeiBaklanDiamond Contributor
Okay, I found it on the feedback. Will play a bit and vote.
- SergeiBaklanDiamond Contributor
Idea is interesting, but the script is unshared. Could you add it to the post or share by other way?
- mtarlerSilver Contributor
I thought you could/would find it in the file but good point I added it here too. I'm still learning what is shared in the workbook itself vs. lives online
- SergeiBaklanDiamond Contributor
it's shared through your OneDrive permissions, not with the file.
I upvoted and added few comments.
I voted for your suggestion.