Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

AutoFill with Office Scripts

Hello people! I'm trying to autofill columns, but getting an error, that the range is incorrect, but it is exactly the same I get when I'm using the record function with Office Scripts, maybe you could help me to figure out what is happening. My code is:



function main(workbook: ExcelScript.Workbook, formulaRange: string, rangeToFill: string)
  let selectedSheet = workbook.getActiveWorksheet();
  // Auto fill range
    .autoFill(rangeToFill, ExcelScript.AutoFillType.fillDefault);



Also, I'm using the compose connector with string() to enter the range and to make sure that it is a string type. 

Super User II
Super User II

Hi @victor_lion,


If I understand the autofill method correctly the rangeToFill also needs to included the cells from your formulaRange string. What values for the rangeToFill and formulaRange were you using in your test?




In other words, if formulaRange is A1:C1, then rangeToFill can't be A2:C7. I think rangeToFill then needs to be A1:C7, including the original cells, if that makes sense?

Helper I
Helper I

I also tried that and it won't work, but if I use a script with setFormulaLocal it works just fine, but I wonder why this version won't work at all...

Super User II
Super User II

Hi @victor_lion,


Just to double check, can you share a couple of screenshots of your flow setup.


This way I can try and reproduce it by exactly recreating your flow setup.

Helper I
Helper I


This is the flow, and the excel is as follows:


Colunas autoFill has the columns that I'm looping the actions



@{outputs('Colunas_autoFill')[variables('cont')]}@{sub(variables('lengthRazaoGeral'), 20)}:@{outputs('Colunas_autoFill')[variables('cont')]}@{variables('lengthRazaoGeral')}



@{outputs('Colunas_autoFill')[variables('cont')]}@{add(1, variables('lengthRazaoGeral'))}:@{outputs('Colunas_autoFill')[variables('cont')]}@{add(variables('lengthRazaoGeral'), variables('lenghtImport'))}


Thinks this might help.

Helpful resources

MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (1,627)