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 doesn't ...
Power Automate
Unanswered

Office script doesn't seem to work as intended in my flow

(0) ShareShare
ReportReport
Posted on by 15

I used the "record actions" feature in excel to create an Office Script that separates data into multiple columns using the Text to Columns Wizard. When recording actions for this script, I only used 3 rows of data and intended for the script to affect the entire first column (A) for when I eventually run it on hundreds of rows in a Power Automate flow. My script is attached below and I'm not sure what I need to change to get the range of non-empty cells in the A column.

function main(workbook: ExcelScript.Workbook) {
	let selectedSheet = workbook.getActiveWorksheet();
	// Text to columns on range A1:A3 on selectedSheet
	for (let row = 0; row < selectedSheet.getRange("A1:A3").getRowCount() ; row++) {
		let sourceRange = selectedSheet.getRange("A1:A3");
		let destinationRange = selectedSheet.getRange("B1");
		let sourceRangeValues = sourceRange.getRow(row).getValues()[0][0].toString().split(/[,]/)
		destinationRange.getOffsetRange(row, 0).getResizedRange(0, sourceRangeValues.length - 1).setValues([sourceRangeValues]);
	}
}

All of my data will be entered one after the other, so the first empty row will mark the end of the column.

 

This also might not be the correct forum to ask this question, so if there is a forum I should post to instead, please tell me in the replies and I will move my post there!

Categories:
I have the same question (0)
  • Verified answer
    v-bofeng-msft Profile Picture
    on at

    Hi @Wes_G ï¼Œ

     

    Please try:

    function main(workbook: ExcelScript.Workbook) {
    	let selectedSheet = workbook.getActiveWorksheet();
    	let selectedRange = selectedSheet.getRange("A1").getExtendedRange(ExcelScript.KeyboardDirection.down);
    	let rowCount = selectedRange.getRowCount();
    	for (let row = 0; row < rowCount; row++) {
    		let sourceRange = selectedRange;
    		let destinationRange = selectedSheet.getRange("B1");
    		let sourceRangeValues = sourceRange.getRow(row).getValues()[0][0].toString().split(/[,]/)
    		destinationRange.getOffsetRange(row, 0).getResizedRange(0, sourceRangeValues.length - 1).setValues([sourceRangeValues]);
    	}
    }

     

    Best Regards,

    Bof

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 523 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 406 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard