Python Forum
How to apply VLookup formula
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to apply VLookup formula
#1
Hello,

I am learning to apply VLookup in Python and in this short example trying to pull full names of the states when I pass the short names. For example SC should return South Carolina and TX should become Texas. States sheet has short names and Full Name sheet is where lookup value is coming from. According to my research I am using the correct formula syntax but after this program runs it keeps saying circular error and there is something wrong with this formula. Can someone please provide me some guidance.

Here is the code:


from os.path import join, dirname, abspath
import openpyxl as op

# open the destination file for writing 
fpath = join(dirname(dirname(abspath(__file__))), 'C:\\', 'States.xlsx') 
dWB = op.load_workbook(fpath)
ST    = dWB['States'] 

for row in ST['A2:A3']:
    for cell in row:
        cell.value = "=VLOOKUP(A{0}, 'Full Name'!A2:B4, 2, FALSE)".format(cell.row)

dWB.save(fpath)
Thanks
Reply
#2
Please be more precise. Please give the complete error message and on which line in the part of the code you show us.
Reply
#3
There is not enough information here to help you.
You need to post a sample of States.xlsx along with your circular error in its entirety.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Vlookup function in Pyhton antozas 1 665 Oct-02-2023, 04:16 AM
Last Post: vikraman
  "Vlookup" in pandas dataframe doug2019 3 1,898 May-09-2022, 01:35 PM
Last Post: snippsat
  Python VLookup? Lookup Table? Nu2Python 3 2,458 Oct-25-2021, 08:47 PM
Last Post: Nu2Python
  Python “Formula” Package: How do I parse Excel formula with a range of cells? JaneTan 1 2,711 Jul-12-2021, 11:09 AM
Last Post: jefsummers
  IF statement to apply at each date illmattic 2 2,690 Apr-08-2021, 12:31 PM
Last Post: illmattic
  trying to do a vlookup in pandas eeps24 1 1,968 May-22-2020, 02:10 PM
Last Post: eeps24
  Issue in .apply function fullstop 0 1,521 Dec-17-2019, 01:29 PM
Last Post: fullstop
  Apply a function with pandas Jompie96 2 2,244 Jun-13-2019, 07:04 PM
Last Post: Jompie96
  VLOOKUP Equivalent using openpyxl DJBuck 2 9,196 Mar-17-2019, 02:03 PM
Last Post: DJBuck

Forum Jump:

User Panel Messages

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