I have a workbook with the following apperance:
This workbooks first sheet, "Resultat", calculates data from the other sheets in the workbook and presents them as the picture shows.
In order for the calculations to work correctly, the names shown in the marked red squares must be the same and corresponding, else the value will be ##### as you can see for entry number 2 (cell A5 works and have the same name as sheet number 2, but cell A8 do not work because it does not have the same name as sheet number 3).
My question is basicly, is it possible to use a function that will enter the name of a sheet in a specific cell. In this example, I would like the cell A5 automaticly fetch the name of the sheet with index 2, cell A8 be equal to sheet with index 3 and so on.
Right now im doing this manually but it would be a great help if this could be automated since I have alot of these workbooks and the names changes from time to time.
Use this formula
=MID(CELL("filename",A1), FIND("]", CELL("filename", A1))+ 1, 255)
The above will give you the name of the current sheet
If you change the reference of A1 to the relevant sheet then it will pick up that name.
Ex:
=MID(CELL("filename",Sheet1!A1), FIND("]", CELL("filename", Sheet1!A1))+ 1, 255)
This will give you Sheet1
Create a VBA module and enter the following code:
Public Function SheetNameByIndex(Index As Integer) As String
SheetNameByIndex = ActiveWorkbook.Sheets(Index).Name
End Function
now, at any place in your workbook, you can do
=sheetnamebyindex(2)
=sheetnamebyindex(A1)
Related
Looking to select multiple choice options from a drop down box.
I have this sample spreadsheet
https://docs.google.com/spreadsheets/d/1BKWZWHRvdLIc8k3MzT4ARENe2s-qD-AW5vegOMs_jqw/edit?usp=sharing
The Clear and Submit buttons should not be a problem.
I am having issues that when I click on "Add another ATA" button, I would like an app script to move the value in D7 to the next available blank cell in the range J2:J13 and then remove the value in D7 to await a new value, then click "Add another ATA" and move the new value to the next available blank cell in the range J2:J13 etc...
I have succeeded in moving the value from D7 to J2 for example.
I cant figure out how to establish via app script how to calculate what cells are blank or not so I know where to insert the code.
I have tried putting the Range J2:13 in an array and cycling through it but I wasn't successful identifying the next available blank cell range.
You can do that with the appendRows_() utility function. Paste it in your script project and call it like this:
const sheet = SpreadsheetApp.getActiveSheet();
const data = sheet.getRange('D7').getValue();
const result = appendRows_(sheet, data, 10);
...where 10 means column J.
I'd like to IMPORTRANGE("http://page","Sheet!A11:F")
Where the page is a link located in a cell on the current sheet, and the range is also in a cell on the current sheet.
For example: IMPORTRANGE("'C8'","'A1'!All:F") Something like that.
My overall goal is to be able to copy the current workbook, add a sheet, put a reference number in A1, then have the sheet automatically pull data (using an A1 vlookup from a master list) from the correct sheet in another workbook without having to manually relink eveyrthing. Just want to put the unique ticker in A1.
The application is there is a 'Master Deal List' workbook. Each row has a different deal with a unique 3 digit 'ticker' in Column A and the deal's sheet in another workbook link in column F. This second workbook (Deals) with distribution data named with the same 3 digit ticker. Finally each investor in each deal has a 3rd workbook which needs to pull distribution amounts from the right sheet in the Deals workbook.
Got it, answer is here:
https://infoinspired.com/google-docs/spreadsheet/dynamic-sheet-names-in-importrange/
Answer:
IMPORTRANGE("http://page", A1&"!A11:ZZ")
I am attempting to use a query to display data off multiple Google Sheets. I make a new sheet every week that has a specific sheet name, e.g. Week of 01/13, Week of 01/06 and so forth.
The following is where my idea spawned from for reference:
I have a summary sheet that is using COUNTA(INDIRECT("'" & A5 &
"'!E4:E",true)
A5 being a cell that concatenates a date and words to replicate the
sheet names.
The row on the summary sheet does not populate until B5<=today()
So I am able to set it an forget it and the sheet will continue to
give me my weekly data as the days progress and keeps the sheets clean
until the week is upon us.
Long story short, I have a query that I use that gives me all the data I need with a specific parameter but I have to manually update the data syntax array with the new sheet names each week.
=QUERY({'Week of 01/13'!A:P;'Week of 01/06'!A:P;'Week of 12/30'!A:P;'Week of 12/23'!A:P;'WEEK OF 12/16'!A:P;'WEEK OF 12/09'!A:P;'WEEK OF 12/02'!A:P;'WEEK OF 11/25'!A:P;'WEEK OF 11/18'!A:P;'WEEK OF 11/11'!A:P;'WEEK OF 11/04'!A:P;'WEEK OF 10/28'!A:P;'WEEK OF 10/21'!A:P;'WEEK OF 10/14'!A:P;'WEEK OF 10/07'!A:P;'WEEK OF 09/30'!A:P;'WEEK OF 09/23'!A:P;'WEEK OF 09/16'!A:P;'WEEK OF 09/09'!A:P;'WEEK OF 09/02'!A:P},
"Select * where Col11 = 'RD' order by Col2 desc",0)
I would like to build a reference to an array that will auto-populate a concatenation based on the day.
Using the following code I can have the concatenate give me the array I need,
=if(H4<=today(),CONCATENATE("'",H$1,text(H4,"mm/dd"),"'!A:P;",),"")
but when I try to input it into the query function it just returns the concatenated text:
=QUERY(I1,"Select *")
'Week of 01/06'!A:P;'Week of 01/13'!A:P
I have tried with and without the curly brackets with no success.
I would like the sheet to be able to refresh and see that it is the correct day, the new sheet name is populated and the query gets updated.
I need help with making I1 work.
Link to Test Query Sheet
dudes who copy-pasted INDIRECT function into Google Sheets completely failed to understand the potential of it and therefore they made zero effort to improve upon it and cover the obvious logic which is crucial in this age of arrays.
in other words, INDIRECT can't intake more than one array:
=INDIRECT("Sheet1!A:B"; "Sheet2!A:B")
nor convert an arrayed string into active reference, which means that any attempt of concatenation is also futile:
=INDIRECT(MasterSheet!A1:A10)
————————————————————————————————————————————————————————————————————————————————————
=INDIRECT("{Sheet1!A:B; Sheet2!A:B}")
————————————————————————————————————————————————————————————————————————————————————
={INDIRECT("Sheet1!A:B"; "Sheet2!A:B")}
————————————————————————————————————————————————————————————————————————————————————
=INDIRECT("{INDIRECT("Sheet1!A:B"); INDIRECT("Sheet2!A:B")}")
the only possible way is to use INDIRECT for each end every range like:
={INDIRECT("Sheet1!A:B"); INDIRECT("Sheet2!A:B")}
which means that the best you can do is to pre-program your array like this if only part of the sheets/tabs is existant (let's have a scenario where only 2 sheets are created from a total of 4):
=QUERY(
{IFERROR(INDIRECT("Sheet1!A1:B5"), {"",""});
IFERROR(INDIRECT("Sheet2!A1:B5"), {"",""});
IFERROR(INDIRECT("Sheet3!A1:B5"), {"",""});
IFERROR(INDIRECT("Sheet4!A1:B5"), {"",""})},
"where Col1 is not null", 0)
so, even if sheet names are predictable (which not always are) to pre-program 100+ sheets like this would be painful (even if there are various sneaky ways how to write such formula under 30 seconds)
an alternative would be to use a script to convert string and inject it as the formula
A1 would be formula that treates a string that looks like real formula:
=ARRAYFORMULA("=QUERY({"&TEXTJOIN("; ", 1,
IF(A3:A<>"", "'Week of "&LEFT(A3:A, 5)&"'!A1:D5", ))&
"}, ""where Col1 is not null"", 1)")
further populating of A6:A will expand the string automatically
then this script will take the string from A1 cell and it will paste it as valid formula into C5 cell:
function onEdit() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Master Sheet');
var src = sheet.getRange("A1");
var str = src.getValue();
var cell = sheet.getRange("C5");
cell.setFormula(str);
}
of course, the script can be changed to onOpen trigger or with custom name triggered from the custom menu or via button (however it's not possible to use the custom function as formula directly)
If you're trying to update the data your query is looking at and you're feeding it a string, you need to put that string within the indirect() function. That will interpret your string as a data reference and point your query() in the right direction.
So for this you'd probably have
=QUERY(INDIRECT(I1),"Select *")
I am trying to copy data from a sheet (SheetA) to another sheet (SheetB)
However, I need the row of the cell to be copied (From Sheet A) to be based off of another cell.
For example:
SheetA has data on A1, A2, A3, A4 etc...
SheetB has a cell (B1) that a user types in a value.
When the script is run the data from SheetA will be copied from column A and a row based off of the value in B1 to SheetB.
So if a user types "5" into B1 and runs, the data from A5 will be copied from SheetA to A1 on sheetB
Here is a script that I have so far, how do I modify this correctly to complete the code?
//Moves data from SheetA -> SheetB;
SheetA.getRange("?").copyTo(SheetB.getRange("A1"));
What do I have to replace where the '("?")' is?
Thank you!
Using setValue() instead will be easier to implement and understand.
Try to implement like below:
Get the value of the input from SheetB
var inputValue = SheetB.getRange(SheetBRow, SheetBColumn).getValue();
-
Use the inputValue as a row parameter for getRange() to get the value
of a cell from SheetA
var SheetACellValue = SheetA.getRange(inputValue, SheetAColumn).getValue();
-
Set the value of a cell on SheetB using the value from SheetACellValue
Cell SheetBCell = SheetB.getRange(SheetBRow,SheetBColumn);
SheetBCell.setValue(SheetACellValue);
You can implement this by method chaining. I just divided each for a better view and understanding.
Assuming you defined SheetA and SheetB and the copyTo Range is fixed (A1) this is your code (following the syntax in your attempt):
SheetA.getRange('A'+SheetB.getRange('B1').getValue).copyTo(SheetB.getRange('A1'));
or (using setValue instead of copyTo because you are adressing one specific cell):
SheetB.getRange('B1').setValue(SheetA.getRange('A'+SheetB.getRange('B1').getValue));
This is basic knowledge when working with Apps Script and Sheets. I recommend you read up on the SpreadsheetApp Documentation.
Moreover this is a duplicate of so many similar questions. Next time search for your question using the google-apps-script tag.
Please help this non-expert -- his job depends upon it.
I have a Google Form that feeds answers into a sheet on a Google Spreadsheet -- let's call it the "main sheet." One of the form's questions asks for a job number. I have been able to figure out how to take each unique job number respondents have entered and create a sheet by that name in the same spreadsheet. I even have copied the headers for the form's answers at the top of each of the new sheets.
What I cannot get to work is rifling through all of the answers in the main sheet, sans the column headers, and copy the rows to the sheet names based on a conditional match with the job number value equaling the sheet name value. So if someone applies for job number 65, that response gets copied from the main sheet to sheet with the name "65."
For starters, I may have the loops set up incorrectly, trying to exclude the header in the main sheet and creating the array of all of the sheet names.
But a second problem I have is that I need to use the variables for both the sheet name value and the job number value. I need to be able to account for an ever increasing job numbers. Staff do not want to have to create a new sheet with every new job number -- they want that done automatically when a user fills in a new job number.
I am happy to share my work, as it is, with anyone who can help point me in the right direction.
+++
Solved, so I yanked down the link to the spreadsheet. In spite of myself, it appears, this community was able to help me out. Thanks.
This function that I wrote will help you find your job number:
function searchColumn(value, rangeValues) {
for (var i = 1; i < rangeValues.length; ++ i) {
if (rangeValues[i] == value) return i;
}
return -1;
}
Give it an array of values (usually by Range.getValues()), and the value you want to search and it will return the row number where that value was found. If it didn't find it, it returns -1.
example:
// Gets all data in the first column of the sheet
var valuestoSearch = mySheet.getRange(1, 1, sheet.getLastRow()).getValues();
// then
var rowNum = searchColumn(job_number, valuesToSearch);
Now that you have the row number, you can use:
var rowData = mySheet.getRange(rowNum, 1, 1, mySheet.getLastColumn()).getValues();
This will give you all the values in that row up to the last column in the sheet.
Once you have that data, you can copy it to another sheet by using:
var jobSheet = mySpreadsheet.getSheetByName(job_number);
jobSheet.getRange(jobSheet.getLastRow() + 1, 1, 1, rowData.length).setValues(rowData);
Or something very similar to this. Then you may want to erase the data in the old spreadsheet so that you don't keep repeating the same operation. But that's up to you how you want to handle that. Take a good look at the documentation for SpreadsheetApp, as it has everything you're looking for and more :)