So I've got a simple problem that I cannot seem to find a simple solution to. Basically what I want to do is have a formula that will find the first instance of a specific value (e.g "ADC") that occurs in a certain range (A1:Z1000), and give me the A1 notation for that cell's position in that sheet. I've tried Index&Match but that is column/row dependent, Regex, Find, etc. but none of those work. I just want it to go cell by cell and report back the absolute location (in the sheet) of the cell that has the first instance of that value. Any help would be appreciated. Thank you
function NEEDLEINHAYSTACK(needle) {
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var rg=sh.getDataRange();
var r=rg.createTextFinder(needle).findNext();
return r.getA1Notation();
}
Related
I have recorded a macro that adds formula onto the end of a cell
function addpricemultiplier() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('H5:1000').activate();
spreadsheet.getCurrentCell().setFormula('=0.3*GOOGLEFINANCE("CURRENCY:USDAUD")');
spreadsheet.getRange('H5:1000').activate();
};
The problems I have are that it will only change if the value is =0.3, I am unsure how to change it so that it will add the formula on no matter what, and of less importance I have made the macro from H5 onto 1000, I am unsure if there is a way to make it just go on as long as the sheet is there instead of pre determining where it will go to.
I am super new to Google Apps Script, and the Java it's based on. In fact I just dived into the deep end of the pool not even eight hours ago! I know VBA, SQL, etc, but I digress.
I've figured out how to change the background color of row when the cell contains a certain value. I can also change the color if the value changes to something else. What I can't do is unchange the color if the value is deleted.
How do I use google apps script to test for a blank cell?
Try this:
function getMyColorValue()
{
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('My Sheet Name');
var rg=sh.getRange('A1');
var colorValue="#ffffff";
if(!rg.isBlank())
{
colorValue=rg.getValue();
}
rg.setBackgroundColor(colorValue);
}
I want to share the sheet with others but i also want them to not able to see some columns. Is there any way out to solve this using google apps script or if any alternate option for the same. Thank you.
You should take a look at the documentation, it will help you to find the function you're looking for. In this case, you need the Sheet.hideColumns(columnIndex) method
hideColumns(columnIndex)
Hides the column at the given index.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Hides the first column
sheet.hideColumns(1);
Very simple function
function onOpen(){
ss = SpreadsheetApp.openById( 'sheetid' ),
sheet = ss.getSheetByName('sheet_name'),
ss.getActiveCell();
sheet.hideColumns(start_column_number, end_column_number);
}
If the columns to be hidden are part of a merged column set, the hide columns methods don't work unless you hide all the columns in the merge.
Google Spreadsheet doesn't have the functionality to "insert cut cells" like in Excel.
Let's say I selected A4 to B5, hit Ctrl+X.
Then I moved the selection to A2.
Now I want to "insert cut cells", probably by inserting blank cells and moving the dotted-range to A2.
Is there any way to do it using JavaScript on your own menu?
eg.
function insertCutOrCopiedCells(){
var SS = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SS.getActiveSheet();
var cell = sheet.getActiveCell();
// How do you get the cells being cut/copied? (ie. A4 to B5)
// We can then insert empty cells (2 cols 2 rows) at the selection (A2)
// and move the cut cells (A4 to B5) there
}
To achieve the insert cut cells feature in google sheets you simply use drag and drop. First highlight the row(s) you want to move then mouse over the row number (you will see a hand icon); then, holding your left-click, and keeping your mouse over the row numbers, you will see a dark line where the insert will take place. Let go of your mouse button and voila.
You have both methods, check'em in the class Range.
moveTo(target)
Cut and paste (both format and values) from this range to the target range.
copyTo(destination)
Copies the data from a range of cells to another range of cells. Both the values and formatting are copied.
Edit:
To complete the function you'll have to use also:
insertRowsAfter(afterPosition, howMany) in class Spreadsheet
Inserts a number of rows after the given row position.
and
getActiveRange() with getRow() to check where's the selection at:
Returns the range of cells that is currently considered active. This generally means the range that a user has selected in the active sheet, but in a custom function it refers to the cell being actively recalculated.
Since you don't have direct acess to the clipboard, you'll have to set up a sidebar, or a modelessDialog, which asks for a range to copy from, and it would paste into the selected area, or the other way around, paste the current selected area onto an inputed ROW.
I think , you can separate the function.
Copy : use getRange with getValue:
link => https://developers.google.com/apps-script/reference/spreadsheet/sheet
Delete data : use the getRange with setValue = blank
example :
var Spreadsheet=
SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName("number1");
var value = Spreadsheet.getRange(1,0).getValue(); // copy
Spreadsheet.getRange(1,1).setValues(value); // insert
Spreadsheet.getRange(1,0).setValues("");
You can use the metho copyTo
example :
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("A:E").copyTo(sheet.getRange("F1"), {contentsOnly:true});
}
Is there a way to get cell note value and display the all the note in the cell next to it?
I have a column C where some of the cells contain note. I would like to get these note value and write each cell note in the cell next to it in column D.
For example: if cell C4 has a note "No entry", I want to display "No entry" in D4.
Thanks.
Alex
I needed to do this today and found your question but no answer. This is what I finally came up with. You can do this by setting up a function in the script editor named getNote.
function getNote(cell)
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getRange(cell)
return range.getNote();
}
then in your spreadsheet enter:
=getNote("C4")
to get the note from cell C4. If you want it to be a reference that changes when you move around the cells, then reference it this way:
=getNote(Address(row(C4), column(C4)))
Word of caution: Notes don't trigger a refresh, so if a note is edited the cell does not pick up the new value right away