Sum of cells above the current one, including any rows inserted later - google-sheets

Now sure there may be better ways to do this but these are just questions of curiosity.
What is the placement of a cell itself called? Its address? Its placement?
Let's say I wanna add all the costs in D26 to D28 and show it in D29(total cell). I can just put in D29
=SUM(D26:28)
but let's say I'm constantly adding rows above under D28 but before D29. So instead I wanna make it so that the total cell can self-identify itself, then find the cell right above it, then add everything from D26 to the cell above the total cell.
=SUM(D26:28)
That is basically what I am trying to achieve.
Please answer if possible in a way that works for google spreadsheets.

This can be done with
=sum(D26:indirect("D"&(Row()-1)))
where indirect("D"&(Row()-1)) references the cell in column D with row number one less than the current row.
"D28" is called the address of a cell (in "A1 format", to be precise). The function indirect takes a string as its argument and returns the reference to the cell with the address given by that string.

Related

apps script sheets : First and last non-empty cell of the current row

I'm looking for a script that allows me to find the first nonblank cell of the current row (regardless of which row I'm in).
Once this cell is found, I would like to give it attributes like for example with setBorder.
I would then like to do the same with the last non-blank cell of the current row.
Finally, I would like to give another attribute to the cells in which I have data.
All this on the current row I'm on.
I hope someone can help me :) if I was not clear enough in my request, I remain at your disposal.
I thank you in advance.
good to you.

How do I create a variable with a formula in a cell but when i call it everything that isnt absolute changes its row number to the current row?

This is the formula I wish to call as a variable.
I wish to call this variable within a formula because its used 4 times in a single larger formula. The problem is when I call it, despite it being the same text it doesn't work I suspect because the cell coordinates don't change to the row its being called to, is there anything that can be done?

UICollectionView scroll to specific cell

i try to create a UICollectionView who should open at a specific cell.
My approach is to store all cells:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) ->
UICollectionViewCell {
// my code
cells.append(cell)
return cell
}
then find the desired cell in viewDidAppear:
let result:[MyCell] = cells.filter{ $0.myProperty!.uuid == selectedUUID }
Unfortunately the desired cell can't be found within the cells array, because not all cells are stored yet.
Am i going in the right direction or do i need a different solution?
EDIT: removed misleading information
Don't work with the cell themselves.
Your cells are displaying data, right? They must. That data (could be numbers, or text, or an image, anything) should be a custom object.
For example, you're displaying a list of animals.
So you have the Animal class, with different properties (Size, weight, age). Again, all an example. Maybe you're displaying a list of students which have a FirstName, Lastname, and so on. Lets say we're using the Animal.
You have an array of Animal objects, you can have 1, or 4, or 234234, it doesn't matter. The array can hold as many animals as you want. But you only have one array.
Your collection view (or tableview) needs to create a cell for each row. How many rows?! Easy, the other methods tells us there are a specific number of rows per section. Let's say we only have one section.
How do you define rows? You give him a number. What number? The number of animals in your array. For example, 5. Or, much better, myAnimalsArray.Count. Now if you have 20 animals, you'll have 20 cells. If you have 3 animals, you'll have 3 cells.
Okay, now to the cells, you know how many you have, and the cellForRow will therefore create X cells, X being the count of your array.
You'll probably have a simple cell for testing, like
cell.title = animal.name
and then return the cell. It's all pseudo code here, but you get the idea.
Now to your actual question
I've written all that because, according to your other comments in the other answers, you seem pretty confused.
You have your animal array (the data), and no cells yet. You want to start on the animal that has a name starting with E, for example. Well, after you've all the animals on the array, you need to find the one that starts with E (or any other filter you might like). You find it with a searching method. Once its done, you will know the index of the animal in the array. It's the array item number 23, it's the Elephant.
Create an NSIndexPath object with section 0 and index 23 (because your filter found it's the 23rd item, again, i'm just using examples), and pass that indexPath object to the scroll method of the collectionview.
And you're good ;)
Do that in the ViewDidLayoutSubviews or viewDidAppear. (first one is better). But you must do it after your array of animals is loaded, otherwise you won't have any data to filter.
Once you've called the method in the link above, your collectionview will scroll, and if you've done it soon enough, it will load at that index and not at index zero.
i have solved this problem through this code hope it will helpful for you:
[self.collectionview setContentOffset:CGPointMake(0,self.collectionview.contentSize.height-self.collectionview.frame.size.height/2) animated:YES];
set above only parameter to contentsize:CGSizemake(x,y);
by adjusting your required parameter you can scroll to specific cell.
just replace above parameter inplace of c and y in contentsize:CGSizemake(x,y); method.
and you have to adjust parameter.
UICollectionView's cell is reused.
For example, if view can only show 3 cells once: A, B , C; then ur cells maybe like [A, B, C, A, B, C, A, B, ...];
each time, u set the property of cell, uuid will be reset to a new value.
so u cant filter out what u want.
Hitendra Hckr is right, u should "filter data array instead of filtering cells array".
Or u can "alloc" new cell instead of "dequeueReusableCellWithReuseIdentifier:forIndexPath:".(Not recommend)
For your case, you need to filter data array instead of filtering cells array, this way you can get exact index.
Based on the filteredIndex create indexpath using below method,
NSIndexPath(forItem: filteredIndex, inSection: yourSectionIndex)
This way you can scroll to particular cell.
Try adding a call to collectionView.reloadData() before scrollToItemAtIndexPath. This will ensure all required cells are created.

Cyclic loading of custom cells Swift

I've been trying to get some response from stack on this issue for a while now with no success.
So i will try to be very precise.
I have an uitableview with two custom cell nibs. Data source for both are two separate arrays (questions array and answers array).
The first custom cell contains uilabel (question cell) and another one uibutton (answer cell).
On launch of the app a specific amount of question cells load up (depending on the amount of objects in the array) and after them the 1 answer cell loads up.
Here is the pic
after click answer2 - again the same procedure happens producing new question cells below as well as the answer3 cell
Don't know how to achieve that.
Thank you!
This is not that hard as it seems. So, on the launch of the app, you load the initial questions and answers. For that you would need the number of required cells, say, 3 questions and 1 answer, totally you need to return 4 from the numberOfCellsInSection:. And, when the user taps(selects, press) the answer row, you just increase the number of cells on the table, if you have 2 questions and 1 answer on the next cycle, now you would return 7 from the numberOfCellsInSection: datasource method of the tableView. And so on.
Also, you can divide the each question-answer into the sections, if you want to have more organized way of achieving your goal. In this case, you have to increase the number of sections in the table, and return proper number of cells for each section on answer cell selection. Use numberOfSectionsInTableview: and numberOfCellsInSection methods of the datasource for this.
Don't forget to draw (set proper texts to the cell's labels, image if any) the data on cellForRowAtIndexPath: method to reflect the correct data on your cells.

Use last value from a specific Cell

I've looked everywhere for a solution with no joy and with no experience with Spreadsheet functions to figure this out myself, I've turned to asking it here.
Basically i need to display the previous value of a cell in another: I.E.
If cell B3 changes from 50 to 60, i need cell G3 to show 50.
I've tried:
=INDEX(B3:B; COUNT(B3:B))
with no joy.
we cant save data permanent when you delete your data in your sheet it wont save another place or it won't display anywhere

Resources