first make sure you got the data from the gsheet? you are using csv method of calling the data. It will work if you set the permission to your sheet to minimum viewer option else you will get error
after getting the data then apply your if then logic. remove now all the logic and then after confirming each and every step then start to add one by one your logic. Never try the whole logic at once else you will feel immense pressure to handle. Every stage you should be knowing what is happening