Excel Fill Range - Using sheet name variable in formula

Out of the several worksheets I am having, I retrieve one particular sheet name based on a fixed pattern and store it in a variable. Subsequently, I want to use this variable in the Fill Range activity wherein the SUMIF formula is being used.

=SUMIF('sheet_name'!A:A,C2,'sheet_name'!R:R)")

But this is not working as the variable value is not getting used in place of sheet_name. I have verified that the variable is properly assigned outside this activity.

@gischethans

If you want to use variable then

You have to add it in the formula using + or append it

Eg =Text(“123”,“000”) is the formula for converting to text then if you want to variablize and pass in UiPath you have to do as follow

"=Text(""" + variable + """000"")"

Double quotes are escaped using a extra double quote

Hope this helps

Cheers

1 Like

This approach is working partially i.e., the sheet name variable is appearing in the formula but I am still facing an error -

The data you want to write "=SUMIF("Sheet-Work" !A:A,C2, "Sheet-Work" !R:R)" has a wrong format.

I entered it as
"=SUMIF(""" + sheet_name + """ !A:A,C2, """ + sheet_name + """ !R:R)"

The error box would not have appeared if Sheet-Work gets enclosed in single quotes. I tried different combinations like adding the single quote inside/outside the double quote combination.

Hello @gischethans
Try this

"=SUMIF("+sheet_name+"!A:A,C2,"+sheet_name+"!R:R)"

1 Like

Perfect, @Gokul_Jayakumar, it worked.

I had to make a minor addition i.e., enclose “+SheetName+” within single quotes, as the SUMIF function expects that.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.