New Bug Encountered: Bug using VLOOKUP Google Sheet formula

Guys, I am using VLOOKUP function like this:

=VLOOKUP($B2,Produtos!$B$1:$Q,16,FALSE)

When I click on REGENERATE STRUCTURE button, the Spreadsheet formula is:

VLOOKUP(RC2,Produtos!R1C2:RC17,16,FALSE)

But, when I insert a new register on Google Sheet Table, the formula of the new regisrter column has been changed to:

=VLOOKUP($B3,Produtos!$B$1:$Q3,16,FALSE)

So, the formula is putting the number of line ($Q3) instead of ($Q) only, and the data is not founded.

Someone could help me?

0 3 382
3 REPLIES 3

Hi! Welcome to the community!

Iโ€™m not sure but perhaps AppSheet doesnโ€™t handle the $Q well. An expression like $Q (where the final row number is left off) says โ€œto the last row.โ€ If AppSheet doesnโ€™t understand the โ€œto the last rowโ€ intent, perhaps the issue might be resolved on the Google sheet side. Hereโ€™s an idea:

  1. On another sheet (one that isnโ€™t a โ€œTableโ€ in your app) put a formula like the following in a cell:
    =countif(Sheet1!A1:A,"="&"")+countif(Sheet1!A1:A,"<>"&"")
    This will give you the number of rows in โ€œSheet1โ€. If new rows are added, the number will change appropriately. In my practice sheet, this formula is in A1 of โ€œSheet2โ€.

  2. Use โ€œindirectโ€ to identify the range in your vlookup expression.
    Hereโ€™s my test formula:
    =vlookup(3,indirect(concatenate(โ€œK2:Lโ€,Sheet2!A$1)),2,false)
    In my sheet this produced the same result that =vlookup(3,K2:L1000,2,false) would have produced. But, if new rows get added to the table โ€œL1000โ€ will become โ€œL1001โ€ or whatever.

I havenโ€™t tried this will AppSheet but Iโ€™m guessing thereโ€™s a good chance it will work.

I wonder if anyone knows a better, more efficient way of identifying the last row in a page.

I think there may be a simpler way, after all. Instead of using the complicated

=countif(Sheet1!A1:A,"="&"")+countif(Sheet1!A1:A,"<>"&"")

expression to find the exact number of the last row, just type in a number like 10000 (or maybe 50000) โ€“ a number that is a lot bigger than the current number of rows in the sheet and one that you canโ€™t imagine your sheet will ever outgrow. That should work. I just tried it and it did.

Actually, now I see that indirect wasnโ€™t even necessary:

=vlookup(3,$K$2:$L$10000,2,false)

This seems to be perfectly adequate.

I facing a new problem. When I import a new row I want my formula to change automatically like this:
Formula Cell on Row 1: =vlookup(K2,$K$2:$L$10000,2,false)
Formula Cell on Row 2: =vlookup(K3,$K$2:$L$10000,2,false)
Formula Cell on Row 3: =vlookup(K4,$K$2:$L$10000,2,false)
โ€ฆ
Formula Cell on Row n: =vlookup(Kn,$K$2:$L$10000,2,false)
How do I validate field K?

Top Labels in this Space