Reputation: 1
I am trying to loop over a column in the spread sheet. For each cell in the column I am looping over, I want to multiply the value of the cell by the value in the cell previous in its row (the cell would be the previous cell in the row, i.e I would loop over column 2 and for A2 I would want to multiply the value in that cell by A1, and then this would be stored in cell A3 and the the loop would continue to B2. In B2 I want to multiply the cell value by B1 and store the result in B3 and so on). I then want to store this total value in next cell in the row.
Here is an example of the data I am trying to automate
https://i.sstatic.net/ggjIB.png
I can't seem to finda clear way to do this, is this even possible with pygsheets? Thanky ou for your help, I am at a loss here!
I have figured out how to loop over a single column with just a basic for loop where it returned the individual calues of the column back in a list but I am not seeing how this list generated from the loop could be modified to do the above.
Edit: Here is my code so far. I got it to almost work but the the "cellcount" is not going up with each for loop iteration.
```python
first_column = wks.get_col(3)
first_column_data = first_column[3:]
cellcount = 4
testnumber = "17"
columntotal = "D" + str(cellcount)
columnquantity = "B" + str(cellcount)
wks.update_value(columntotal, testnumber)
for values in first_column_data:
variable = wks.get_value(columnquantity)
quantity = 0
if values == "BARBLON-12":
quantity += 2
else:
pass
stockvalue = quantity * int(variable)
wks.update_value(str(columntotal), str(stockvalue))
quantity = 0
cellcount += 1
```
Upvotes: 0
Views: 86