Page 1 of 1

[Calc, Basic] Format imported database data

Posted: Tue Feb 14, 2023 3:30 pm
by Villeroy
The demo document contains some unformatted demo data, a set of cell styles, two named ranges and a Basic macro triggered by a push button. If you click any cell in the data list and push the button, the macro will detect the current region of used cells around the current selection as the list range to be formatted and will apply cell styles as follows:
The first row gets the cell style whose name is entered into named cell "HeaderStyle" (A1).
The data rows get the cell styles defined in named range "ColumnStyles" (A2:D2).
You can copy the Basic module into your own template. It can also be copied to the public libraries under "My Macros" since the macro applies to any spreadsheet document having the required names and styles.

P.S. The push button in the sample sheet has property "Take focus on click" = OFF because the macro depends on the current cell selection. This fails when the push button takes the focus away from the sheet. This is not a problem when you call the macro from Tools>Macros or from a user defined UI element.