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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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