title: how to rewrite a IF loop statment into openyxl iteration loop
body: <p>I have written this code using a for loop to get data from excel and write back to excel (it didn't work). I was able to save only the last row data. Other data are not saved.</p>
  
  <p>I got to know about iteration method in openpyxl, but didn't got enough resource to learn it.</p>
  
  <p>Could anyone tell me how to rewrite the below for loop into openpyxl iteration?</p>
  
  <pre><code>import openpyxl
  
  for i in range(2,4):
  
  wb=openpyxl.load_workbook('comp.xlsx')
  sheet=wb.get_sheet_by_name('comp')
  url=sheet.cell(i,2)
  print(url.value)
  
  r=requests.get(url.value)
  soup = BeautifulSoup(r.content,"html.parser")
  
  g_data = soup.find_all("div",{"class":"search-page-heading-red"})
  for cname in g_data:
      com=sheet.cell(i,5)
      com.value = cname.text
      print(com.value)
      wb.save('compfinal.xlsx')
  </code></pre>