Here are the styles for changing the seed year column yellow and red
For Style (condition 1) – changing the seed year to Red if older than 5 years.
Formula is:
YEAR(TODAY()) – $D5 > 5
For Style (condition 2) – changing the seed year to Yellow if older than 3 years.
Formula is:
YEAR(TODAY()) – $D5 > 3
The Range Field = $D$5:$D$999
=================================
Macros for Sorting the Spreadsheet
Sub SortByHarvestYear
Dim oSheet As Object
Dim oRange As Object
Dim oSortDesc(1) As Object
Dim sortFields(0) As Object
oSheet = ThisComponent.CurrentController.ActiveSheet
‘ Sort rows 5 through 999 (adjust as needed)
oRange = oSheet.getCellRangeByName(“A5:Z999”)
‘ Sort by Column D (index 3)
sortFields(0) = CreateUnoStruct(“com.sun.star.table.TableSortField”)
sortFields(0).Field = 3
sortFields(0).IsAscending = True
oSortDesc(0) = CreateUnoStruct(“com.sun.star.beans.PropertyValue”)
oSortDesc(0).Name = “SortFields”
oSortDesc(0).Value = sortFields()
‘ IMPORTANT: row 5 is NOT a header
oSortDesc(1) = CreateUnoStruct(“com.sun.star.beans.PropertyValue”)
oSortDesc(1).Name = “ContainsHeader”
oSortDesc(1).Value = False
oRange.sort(oSortDesc())
End Sub
Sub SortByVegetableThenName
Dim oSheet As Object
Dim oRange As Object
Dim oSortDesc(1) As Object
Dim sortFields(1) As Object
oSheet = ThisComponent.CurrentController.ActiveSheet
‘ Sort rows 5 through 999 (adjust as needed)
oRange = oSheet.getCellRangeByName(“A5:Z999”)
‘ Primary sort: Column B (index 1)
sortFields(0) = CreateUnoStruct(“com.sun.star.table.TableSortField”)
sortFields(0).Field = 1
sortFields(0).IsAscending = True
‘ Secondary sort: Column C (index 2)
sortFields(1) = CreateUnoStruct(“com.sun.star.table.TableSortField”)
sortFields(1).Field = 2
sortFields(1).IsAscending = True
oSortDesc(0) = CreateUnoStruct(“com.sun.star.beans.PropertyValue”)
oSortDesc(0).Name = “SortFields”
oSortDesc(0).Value = sortFields()
‘ IMPORTANT: row 5 is NOT a header
oSortDesc(1) = CreateUnoStruct(“com.sun.star.beans.PropertyValue”)
oSortDesc(1).Name = “ContainsHeader”
oSortDesc(1).Value = False
oRange.sort(oSortDesc())
End Sub