How can I efficiently get the first empty cell in a row in google sheets?

Viewed 86

I am trying to find the first empty cell in column A, starting from row 50, and return the row number. Here is what I have so far.

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)

sheet = client.open('SheetName').sheet1

row = 50
for rowNum in range(50, 100):
    cell_value = sheet.cell(rowNum, 1).value
    if cell_value is None:
        break
    row += 1

But it takes almost a full second PER row to get the value. I think it is connecting to google and loading the sheet each iteration in the for loop, and eventually this will have hundred and hundred of lines, and that will take too long. Any way to do this in a better/more efficient way?

0 Answers
Related