'Looping through each cell of a column in Excel using Python

I have an Excel file with data in column A. I want to loop through each cell and stop once i reach the first cell that has a formula.

This is my code:

wb = openpyxl.load_workbook(r"path\filename.xlsx")

sheet = wb['Sheet1'] 

names=sheet['A'] 

for cellObj in names:

  if cellObj.value.str[0] == '=':
     print(cellObj.value)

But i get an error...

The response from @John Giorgio worked for that part.

Now what i'm trying to do next is to select the entire row and paste special.

Here's my code:

import openpyxl 
wb=openpyxl.load_workbook(path1)
sheet = wb['Sheet1']

names=sheet['A']

for cellObj in names:
    val = str(cellObj.value)
    if val[0] == "=":
        #print(val)

        excel.Range("A10:TM10").Select() #PART I WANT TO SELECT IF TRUE 
        excel.Selection.PasteSpecial(Paste=-4163)

So once I come across the first cell with '=' i want to select the entire row or at least from column A to TM and hardcode it / pasteSpecial



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source