Share via

Anyone can help?

Anonymous
2024-11-26T01:06:56+00:00

Request some expert for office script coding in excel. I request to filter and copy the data to another worksheet, the data is variable everytime. Refer to attachment for illustration.

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2024-11-26T02:18:48+00:00

Formula.

=FILTER(Sheet1!A2:C8,Sheet1!C2:C8="AAAA")

For office script, try this one.

====================================================

function main(workbook: ExcelScript.Workbook) { // Get the source worksheet let sourceSheet = workbook.getWorksheet("Sheet1");

    // Get the range to filter

let range = sourceSheet.getRange("A2:C8").getValues();

    // Define the filter criterion let criterion = "AAAA";

// Filter the datalet filteredData = range.filter(row => row[2] === criterion);

// Get the destination worksheet (create it if it doesn't exist)let destinationSheet = workbook.getWorksheet("FilteredData");if (!destinationSheet) {destinationSheet = workbook.addWorksheet("FilteredData");}

// Set the filtered data in the destination sheetdestinationSheet.getRange("A1:C1").setValues([["Cat No", "Amount", "Desc"]]);destinationSheet.getRange("A2").getResizedRange(filteredData.length - 1, filteredData[0].length - 1).setValues(filteredData);}

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2024-11-26T11:35:55+00:00

    This is works perfectly. Thanks Snow. 👍

    Was this answer helpful?

    0 comments No comments