Python Forum
How to apply VLookup formula - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to apply VLookup formula (/thread-23682.html)



How to apply VLookup formula - jonzee - Jan-12-2020

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


RE: How to apply VLookup formula - ibreeden - Jan-12-2020

Please be more precise. Please give the complete error message and on which line in the part of the code you show us.


RE: How to apply VLookup formula - Clunk_Head - Jan-12-2020

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.