Python Forum
Openpyxl tkinter search a value in Excel column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Openpyxl tkinter search a value in Excel column

I am a big beginner in Python, so I hope I will fine a help to resolve my current problem.
Firstly, I am working with Python 3, and I want when the user enter a site ID (format Txxxxx) in ZT1, the program goes to Excel file "My_Excel.xlsx" and search for the site ID in the column "B", and if this value is found, the program should return the value of the Col "I" in ZT2 (of the first row where site ID in Col "B" is found). Kind of Vlookup function.
This is my code to complete:
from tkinter import *
from tkinter import messagebox
import openpyxl
from openpyxl import Workbook
def Verification(*args):
   value = ZT1.get()
   if len(value) != 6 or value[:1] != "T" or not value[1:6].isdigit() :
     messagebox.showwarning("Error", "ID not valide")
   else :
# Put the value of Col "I" in ZT2 (if the ID is found in Col "B" of course)
fen = Tk()
fen.title('Rapports CCU')
Label1 = Label(fen, text = "N° ID :", font = 'times') = 35,y = 16)
Label2 = Label(fen, text = "Region :", font = 'times') = 268,y = 16)
ZT1 = Entry(fen, width = 17, justify='center', bg="#aee6ff") = 155, y = 20)
ZT2 = Text(fen, width = 13, height=1, bg="#c9d4ff") = 405, y = 20)
ZT2.config (state=DISABLED)
wb = openpyxl.load_workbook('My_Excel.xlsx')
ws =
Thanks in advance.

Larz60+ write Dec-02-2020, 06:44 PM:
The tag you should use for multi-line python srcipt is '[python]',
non '[inline]'. I fixed this.
inline is used for a single python statement embedded within a text field.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Openpyxl manipulate excel write formula SamLiu 0 276 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  How to format Excel column with comma? dee 0 461 Jun-13-2022, 10:11 PM
Last Post: dee
  Python, Tkinter, & Excel Extra 2 719 Apr-29-2022, 10:42 PM
Last Post: Extra
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 2,299 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  Appending Excel column value as CSV file name sh1704 0 779 Feb-06-2022, 10:32 PM
Last Post: sh1704
  Find last filled column in openpyxl Irv1n 2 5,046 Jan-16-2022, 11:05 AM
Last Post: Pedroski55
  Trying to search and make new column from the keyword. dgarg 1 793 Dec-20-2021, 08:41 PM
Last Post: deanhystad
  Want to remove the text from a particular column in excel shantanu97 2 1,418 Jul-05-2021, 05:42 PM
Last Post: eddywinch82
  Copy column from one existing excel file to another file mkujawsk 0 2,843 Apr-14-2021, 06:33 PM
Last Post: mkujawsk
  OpenPyxl: How to iterate through each Column (in 1 row) to find a value? chatguy 2 13,879 Apr-06-2021, 04:52 AM
Last Post: carlhyde

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020