Getting error while creating chart in Excel

Hi,
I am getting an error while creating a chart in Excel worksheet. Can anyone please help me in this.

I can see below result in my Console. I guess issue is occurring at line 51 of my code.
Line is data = Reference(sheet, range_string=f’{sheet}!A2:J11’)

Traceback (most recent call last):

File “”, line 51, in
data = Reference(sheet, range_string=f’{sheet}!A2:J11’)

File “C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\chart\reference.py”, line 50, in init
sheetname, boundaries = range_to_tuple(range_string)

File “C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\utils\cell.py”, line 196, in range_to_tuple
raise ValueError(“Value must be of the form sheetname!A1:E4”)

ValueError: Value must be of the form sheetname!A1:E4

Please see below code for your reference.

“”"
openpyxl is a Python library to read/write Excel 2010 xlsx/xlsm/xltx/xltm files.
It was born from lack of existing library to read/write natively from Python the Office Open XML format.
“”"
import openpyxl
from openpyxl.styles import Font #This is required for cell formatting
from openpyxl.chart import BarChart, Series, Reference

wbkName = r’\AA\AA\AA\AA\Python Chart Data.xlsx’# Please change path
wbk = openpyxl.load_workbook(wbkName)

#This loop is used to clear contents of worksheets
for wks in wbk.worksheets:
for row in wks[‘A1:J10’]:
for cell in row:
cell.value = None

for wks in wbk.worksheets:
wks[‘A1’] = ‘A’
wks[‘B1’] = ‘B’
wks[‘C1’] = ‘C’
wks[‘D1’] = ‘D’
wks[‘E1’] = ‘E’
wks[‘F1’] = ‘F’
wks[‘G1’] = ‘G’
wks[‘H1’] = ‘H’
wks[‘I1’] = ‘I’
wks[‘J1’] = ‘J’

ClrNFrmt = Font(color=‘FF008000’, bold=True)
for wks in wbk.worksheets:
wks[‘A1’].font = ClrNFrmt
wks[‘B1’].font = ClrNFrmt
wks[‘C1’].font = ClrNFrmt
wks[‘D1’].font = ClrNFrmt
wks[‘E1’].font = ClrNFrmt
wks[‘F1’].font = ClrNFrmt
wks[‘G1’].font = ClrNFrmt
wks[‘H1’].font = ClrNFrmt
wks[‘I1’].font = ClrNFrmt
wks[‘J1’].font = ClrNFrmt

for wks in wbk.worksheets:# This will write for all the worksheets in workbook
for myRow in range(2, 7):# 6 will give results till row 5 not 6
for myCol in range(1,11):# 11 will give data till column 10
wks.cell(row=myRow, column=myCol).value = myRow -1

sheet = wbk.active
chart = BarChart()

data = Reference(sheet, range_string=f’{sheet}!A2:J11’)
category = Reference(sheet, range_string=f’{sheet}!A2:A5’)

chart.add_data(data, titles_from_data=True)
chart.set_categories(category)
sheet.add_chart(chart, ‘L2’)

wbk.save(wbkName)
wbk.close ()