Python Forum
find empty cells in a column - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: find empty cells in a column (/thread-5087.html)



find empty cells in a column - Pedroski55 - Sep-18-2017

I have a results sheet from a multiple choice marking program. I only need to check if there is no content in a particular cell.

Lets say we are looking at column F of an excel table. Each row from row 2 to sheet.max_row should have an entry, a letter from A, B, C or D. These letters are assigned by a program which marks multiple choice forms.

What I am looking for is cells which have no entry.

for rowNum in range(2, sheet.max_row):
	print(sheet.cell(row=rowNum, column=6).value)
This output looks like this:

Quote:D
C
B
None
D
A
A

In this example, F5 has no content. So I will assign the student number in B5 to studentNumbersWithErrors[]

What I want is to find any cells in all even columns from F onwards which have no content. If there is no content, I want the student number, which is in column B. The row is rowNum. Then I can check in the marking program to see what the problem is. That way, I only need to check if there is a problem.

I've tried:
Quote:if sheet.cell(row=rowNum, column=6).value = 'None':
if sheet.cell(row=rowNum, column=6).value = None:
if sheet.cell(row=rowNum, column=6).value = '':

I keep getting 'syntax error'. Any tips please?


RE: find empty cells in a column - Sagar - Sep-18-2017

You missed double equals to sign (==) inside if conditional statement.


RE: find empty cells in a column - Pedroski55 - Sep-18-2017

Haha, thanks, that did it. I got what I wanted!