KeyError: 'Worksheet a8 does not exist.'

Hello folk

I am new to python, like very new, and this error has me scratching my head. The excel file and work sheets do exist. If I go into idle I can interact with them. I have been running the program without this error and while tweaking code further down this problem raised it’s head. The error pops up about half way down the program at an ’If’ statement, which has been doing a good job until today. Can anyone point me in the right direction as to solve where I went off track. Any help will be most appreciated. Many thanks in advance and enjoy your weekend.

Bob

Can you try using a capital letter? Say A8 instead of lower case a8 when referencing the cell.
If that doesn’t work, you’ll have to provide your script for review.

  • One other small point, maybe it was a typo, but if should be lower case:
1 Like

Hi Paul, Thanks for the reply. I have checked and the “if” statement is in lower case. I have also done a search for ”a8” and there is no reference to it anywhere in the script. I am happy to send the script and Excel file. Do I post it on here?

Once again thank you

Stuart Brown

Did you try capital letter? As in A8?

You can post your script here for review. Make sure that it is properly formatted so that it appears precisely as it does on your terminal. You can do this by pasting your script here, selecting ALL of it (make sure all of it is highlighted), then clicking the “</>” tool above (when in edit mode). This way your script appears like this, for example:

def some_function_here(x, y, z): 
    
    sum_of_three = x + y + z

    print(f'The sum of {x}, {y}, and {z} is: {x+y+z}.')

Hi Paul

Thanks for the assist but it is sorted out.

I am not sure what was wrong but I fixed it. Or should I say it is fixed?

Thanks again

1 Like