web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / office script EXCEL: g...
Power Automate
Unanswered

office script EXCEL: get last row

(0) ShareShare
ReportReport
Posted on by 21

Hello all

 

im doing my first office script:

 

function main(workbook: ExcelScript.Workbook) {
  let selectedSheet = workbook.getActiveWorksheet();
  // Set range Y1:Y2 on selectedSheet
  selectedSheet.getRange("Y1:Y2")
    .setValues([
      ["Date"],
      ["=TEXT(TODAY(),'mm.dd.yyyy')"]
    ]);
  // Set width of column(s) Y1 to 73.5
  selectedSheet.getRange("Y1")
    .getFormat()
    .setColumnWidth(73.5);
  // Auto fill range
  selectedSheet.getRange("Y2")
    .autoFill("Y2:Y52"ExcelScript.AutoFillType.fillDefault);
}
 
and i need 2 things:
 
1. the formula to fill a cell with date fails....im pretty sure that is a problem with quotes
2. i need how to calculate last row to apply the auto fill
 
regards
Categories:
I have the same question (0)
  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @javier_perez 

     

    This community is related to Power Automate. Your question is more focused on Excel formula. 

     

    Please post your question to below community.

     

    The Microsoft Excel Community

     

    Thanks

  • javier_perez Profile Picture
    21 on at

    hello

     

    but the formula works on desktop excel and web excel...the problem is when i execute the script in power automate

     

    regards

  • javier_perez Profile Picture
    21 on at

    for question 1:

     

    i have to escape the quotes with '\' 

    "=TEXT(TODAY(),\"mm.dd.aaaa\")"
  • Yutao Huang Profile Picture
    Microsoft Employee on at

    @javier_perez -

     

    Regarding your question to find the last row, I'm wondering if you have tried Range.getSurroundingRegion( ) . I think that should work as long as there are no completely blank rows or blank columns within the range.

     

    https://docs.microsoft.com/en-us/javascript/api/office-scripts/excelscript/excelscript.range?view=of...

     

    -Yutao

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard