Forum Discussion
ChrisCarpenter
Jan 16, 2024Copper Contributor
Python in Excel iteration of sheets
Hello and thank you for any assistance. I have 1 in A1 and 2 in A2 of Sheet2 Additionally, I have the same setup in Sheet3. for i in range(2,4):
value = f"Sheet{i}!A1:A2"
print(x...
- Jan 18, 2024
Python in Excel doesn't work with such kind of indirect references, i.e.
a = "Sheet2!A1:A2" xl(a)
returns the same error. xl() accepts direct names of the Excel objects.
ChrisCarpenter
Jan 18, 2024Copper Contributor
Thank you for a response.
I would agree with you if it weren't for the fact that it works after another direct loading of those specific cells line pointing to the sheet.
for i in range(2,4):
value = f"Sheet{i}!A1:A2"
print(xl(value))
Does not work for Sheet2, however,
xl("Sheet2!A1:A2")
for i in range(2,4):
value = f"Sheet{i}!A1:A2"
print(xl(value))
For Sheet2 does work
xl("Sheet2!A1:A3")
for i in range(2,4):
value = f"Sheet{i}!A1:A2"
print(xl(value))
Does not work for Sheet2
Very strange.
SergeiBaklan
Jan 18, 2024Diamond Contributor
Python in Excel doesn't work with such kind of indirect references, i.e.
a = "Sheet2!A1:A2"
xl(a)
returns the same error. xl() accepts direct names of the Excel objects.
- ChrisCarpenterJan 18, 2024Copper ContributorSo by extension there is no way to reference all of a particular range across all sheets?
That's a shame. I was trying to convert my py scripts with openpyxl into excel itself.