0

I have an excel file with 18 sheets, 75 columns and 50000 rows.

I am trying a code like this to replace values and it is saying syntax error.

from win32com.client import Dispatch #to work with excel files
.
.
.
.
fnd = "REPLACINGTHENAS"
rplc = ""

#18sheets
for i in range(1, (xlwb1.sheets.count +1)):
    #Syntax error on the line below
    xlwb1.Worksheets(i).Cells.Replace what:=fnd, Replacement:=rplc, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

xlwb1.Save()

I am not sure why there is a syntax error. Kindly help me with this.

2 Answers 2

1

Parentheses are missing around the .Replace() function call. Also, as Dylan correctly pointed out, you should use # to comment lines.

xlwb1.Worksheets(i).Cells.Replace(what=fnd, Replacement=rplc, LookAt=xlPart, SearchOrder=xlByRows, MatchCase=False, SearchFormat=False, ReplaceFormat=False)
Sign up to request clarification or add additional context in comments.

Comments

1

Tip: Use # to comment lines!

I use an module called XLWT in conjunction with XLRD to manipulate spreadsheets, it is simple and flexible. You can try installing the module via pip: https://pypi.org/project/xlwt/

I may be able to help you out a bit more with that!

2 Comments

Thanks for the tip. No, I can't install an external library need a native method. But thanks.
Ah I understand, I am sure Alexander will be able to help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.