[Solved] Macro auto filter Dates in two columns

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

[Solved] Macro auto filter Dates in two columns

Post by Math »

greetings

                       I'm trying to build a Macro for Auto Filter Dates Range in two different columns on the same worksheet

                       for example:

                       the worksheet1 has 5000 rows, column A and column F contains dates

                       I need to filter in column A the date range between 01/15/2008 to 12/20/2015 and in column F I need to filter the date range between 10/03/2008 to 25/12/2010

                       needs to be through macro and need to make the two filters together in the same macro

                       I tried several examples from the forums, but no example is similar to my problem.



                    hugs
Last edited by Math on Mon Nov 19, 2018 11:19 pm, edited 1 time in total.
LibreOffice 5.4.4.2 on Windows 7
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: macro auto filter Dates in two columns

Post by RusselB »

While I prefer to stay away from macros, I'm wondering why you are requiring this to be via macro when the Standard Filter, rather than auto-filter, is more than capable of matching the remainder of your specified requirements.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

Re: macro auto filter Dates in two columns

Post by Math »

I'm building an automation project in LibreOffice for some services that are very manual

so I'm looking for knowledge in LibreOffice


hugs
LibreOffice 5.4.4.2 on Windows 7
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: macro auto filter Dates in two columns

Post by Zizi64 »

Please do not use macros if you want not learn about the API functions (API : Application Programming Interface). Andrew Pitonyak' free macro books will help you.
http://www.pitonyak.org/oo.php

Or try "to record" the macros first. Then you will see it in the recorded code what functions and parameters are in use (what parameters you need pass to a function) in a specific task. The macro recorder has a limited capability - therefore you must WRITE your more difficult macros, but the recorder is a good assistant for the beginners. The macro recorder uses the Dispatcher for everithing, therefore the recorded macros will work slower.

You can control the Standard filter by a macro, too: You can set the filter criteria, and the target of the results by your macro.

Samples, how to use the filters from a Macro code (without the Dispatcher):
viewtopic.php?f=20&t=17037
viewtopic.php?f=45&t=71734
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: macro auto filter Dates in two columns

Post by Villeroy »

This is the documentation of filters: http://www.openoffice.org/api/docs/comm ... iptor.html There are only filters. Auto/standard/advanced filters are just different means to apply some filter from the user interface.
Handling dates in StarBasic is not trivial: viewtopic.php?f=74&t=82181 Spreadsheets don't contain any dates. There are only doubles, strings and error valurs.
Math wrote: the worksheet1 has 5000 rows, column A and column F contains dates
Either you convert your "Excel solution" into a more professional database solution NOW or you stick with MS Excel. What will you do next time when you switch to a third spreadsheet?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: macro auto filter Dates in two columns

Post by Villeroy »

The attachment is another tutorial sheet on criteria ranges (from...until date), advanced filters, d-functions, subtotals and a pivot table.
Knowing how advanced filters work, we can easily use a macro to manipulate the filter criteria in sheet cells before setting the criteria range and refreshing the list with the new criteria set.
My first attachment to this forum (Xmas 2007) includes a macro to assign a criteria range to a database range and refresh on criteria input: viewtopic.php?t=1049&p=4531#p4531
Attachments
AdvDateFilter.ods
Date criteria demo (no macros)
(46.74 KiB) Downloaded 299 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

Re: macro auto filter Dates in two columns

Post by Math »

sr. Villeroy and sr. Zizi64 , thank you very much for the proposed material, I will study the material to see if I can adapt to my problem


hugs
LibreOffice 5.4.4.2 on Windows 7
Post Reply