Python Forum

Full Version: How to apply VLookup formula
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Please be more precise. Please give the complete error message and on which line in the part of the code you show us.
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.