cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
victor_lion
Helper II
Helper II

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
  selectedSheet.getRange(formulaRange)
    .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. 

4 REPLIES 4
Expiscornovus
Dual Super User
Dual Super User

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?

 

autofill_function.png

 

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?

victor_lion
Helper II
Helper II

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...

Expiscornovus
Dual Super User
Dual Super User

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.

victor_lion
Helper II
Helper II

victor_lion_0-1617989036296.png

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

victor_lion_1-1617989089890.png

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

 

formulaRange:

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

 

rangeAutoFill:

@{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

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (3,714)