I'm having the 'TypeError: argument of type 'NoneType' is not iterable and adding an exception doesn't seem to work' error that I've seen elsewhere on here and have found from other answers that it's due to the loop returning a None value but adding a None exception doesn't work and I can't see how else to do this.
I'm using openpyxl with Python3 and have subjects in column A that are updated through another project so could have 0 to multiple lines (I unmerge them all at the start of the script). I need to search all of the rows for each project in column J for dates to copy across to another column, and as column 2 is blank for rows that have been updated I use a for loop with a if statement to add blank rows to an array for later deletion.
All rows that aren't blank, I use the else statement to count in tempList how many blank rows are in that project and then for loop to set myStringTest as the column J value so I can search for the text I want - if I find it I want to copy a slice of the text (a date) across to another column - I just have print('test') here at the moment.
for i in range(2, sheet.max_row + 1):
if sheet.cell(row=i, column=1).value == None:
print('This row has nothing in it')
arrayForDeletion2.append(i)
else:
tempList = 1
x = i
while sheet.cell(row=x+1, column=1).value == None:
tempList += 1
x += 1
if tempList >30:
break
print(i)
print(tempList)
for y in range(i, i+tempList):
myStringTest = (sheet.cell(row=i, column=10).value)
if 'Original' in myStringTest and not None:
print('test')
i += 1
>>>Traceback (most recent call last):
File "main.py", line 113, in <module>
if 'Original' in myStringTest and not None:
TypeError: argument of type 'NoneType' is not iterable
So A2 may have 6 update rows, with J4, J5 and J7 each having a string saying 'Original target date: XX/XX/XX' - I'm looking to recognise that in the if statement and if so to copy out just the date to another column. If no string, do nothing.
That's probably not very clear sorry but I'm fairly new to python and have looked around a lot for an answer but can't work this out. Really grateful for any help. Thanks.