Office script, filter color filled rows

jsmith2094

New Member
Joined
Aug 19, 2021
Messages
35
Office Version
  1. 365
Platform
  1. Windows
Hi All,



I'm trying to make an office script to use with power automate to filter any rows that have a fill color of yellow and then copy those filtered rows to a table on a different workbook.



when I use the record function in excel it records the filter but it doesn't seem to recognise to be able to filter on yellow fill.



Here is my sample code I'm trying to make:



VBA Code:
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheet('Sheet1');



let range = sheet.getRange("A1:A" + sheet.getUsedRange().getRowCount());



let interiorColors = range.getFormat().fill.load(["color"]).values;



let yellowColor = ExcelScript.Color.getColorByRgb(255, 255, 0);



let rowsToDelete: number[] = [];



for (let i = 0; i < interiorColors.length; i++) {
let cellColor = interiorColors[i].color;

if (cellColor !== yellowColor) {
rowsToDelete.push(i + 1);
}
}



if (rowsToDelete.length > 0) {
sheet.getRange("A" + rowsToDelete[0]).getResizedRange(rowsToDelete.length, 1).delete(ExcelScript.DeleteShiftDirection.up);
}
}



any help would be great
:slightly_smiling_face:
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top