21.08.2013 Views

LibreOffice 3.4 Calc Guide - The Document Foundation Wiki

LibreOffice 3.4 Calc Guide - The Document Foundation Wiki

LibreOffice 3.4 Calc Guide - The Document Foundation Wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

After creating one or more sets of filter criteria, apply an advanced filter as follows:<br />

1) Select the sheet ranges that contain the data to filter.<br />

2) Use Data > Filter > Advanced Filter to open the Advanced Filter dialog (see Figure 321).<br />

3) Select the range containing the filter criteria and any other relevant options. Click OK.<br />

Applying an advanced filter using a macro is simple (see Listing 17). <strong>The</strong> cell range containing the<br />

filter criteria is used to create a filter descriptor, which is then used to filter the range containing the<br />

data.<br />

Figure 321. Apply an advanced filter using a previously defined named range<br />

Listing 17. Use an advanced filter.<br />

Sub UseAnAdvancedFilter()<br />

Dim oSheet 'A sheet from the <strong>Calc</strong> document.<br />

Dim oRanges '<strong>The</strong> NamedRanges property.<br />

Dim oCritRange 'Range that contains the filter criteria.<br />

Dim oDataRange 'Range that contains the data to filter.<br />

Dim oFiltDesc 'Filter descriptor.<br />

REM Range that contains the filter criteria<br />

oSheet = ThisComponent.getSheets().getByIndex(1)<br />

oCritRange = oSheet.getCellRangeByName("A1:G3")<br />

REM You can also obtain the range containing the<br />

REM filter criteria from a named range.<br />

REM oRanges = ThisComponent.NamedRanges<br />

REM oRange = oRanges.getByName("AverageLess80")<br />

REM oCritRange = oRange.getReferredCells()<br />

REM <strong>The</strong> data that you want to filter<br />

oSheet = ThisComponent.getSheets().getByIndex(0)<br />

oDataRange = oSheet.getCellRangeByName("A1:G16")<br />

oFiltDesc = oCritRange.createFilterDescriptorByObject(oDataRange)<br />

oDataRange.filter(oFiltDesc)<br />

End Sub<br />

Change properties on the filter descriptor to change the behavior of the filter (see Table 17).<br />

308 <strong>LibreOffice</strong> <strong>3.4</strong> <strong>Calc</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!