How to get the last 10 items from Google Sheets

I want to get the last 10 items from Google Sheets, but so far, it’s not working.
Here’s my code:

I have 13 items in my spreadsheet, so, ideally I should get all the items from the 3rd row to the 13th.

But, this is not working. I’m receiving 13(which is the length of my spreadsheet) as variable i in my alert message. What should I do?

Thanks.

The number of rows from 3 to 13 is actually 11 so I think you instead want rows 4 to 13. But besides that I would expect the Alert to display 3, then 4, then 5, etc.

If it’s only displaying once and only showing 13 then it means that your “count with” loop is completing all of its iterations without pausing for each Alert cycle.

Try adding a wait block and see if the alert appears with different values. Or just use a label and a wait block instead of the alert.

1 Like

Sure! Thanks for that. But even weirder is it’s repeating values and skipping the middle ones.

For example, it’s displaying the values from row 5 twice and then from row 7, without displaying row 6’s values. It’s basically replacing row 6 with values from row 5 again.

If you’re talking about the alert then yes, that’s unexpected. If you mean the Google Sheet values aren’t correct then I think I know why.

You’re asking the create row block to use get value blocks. Those get value blocks are going to take some time to retrieve the value. And the create row block isn’t programmed to wait. To correct that, I would assign the value of the Book name to a variable and then use the variable in the create row block.

In addition, you have a create row block inside of a very fast “count with” loop which probably doesn’t give the create row block enough time to complete… except maybe if the alert pauses everything until you confirm it. Not sure there.

2 Likes

No, what I’m talking about is the data viewer list. My Google Sheet is correct, but the data viewer list is wrong.

This is what I’m talking about:

And my DVL:

I was watching the label closely, and realized that instead of going from 3 to 4, it was jumping from 3 to 5 and 5 was jumping to 7 and not 6.

Here’s my code:

Any ideas for corrections?
Thanks.

If you remove the create row for a moment and test it, does your label count up correctly?

Is that entire set of blocks inside of anything except a simple event block (e.g. when screen opens, when button is clicked)? Because if it’s in a loop as well, that can cause a problem.

2 Likes