I'm self-taught, and apparently not a very good teacher.
I have a workbook with multiple sheets that contains my tasks list. I have buttons that perform specific filters and sorts and, up until I tried a few days ago to resolve the problem I describe in another thread (https://www.mrexcel.com/forum/excel...multiple-columns-post5229747.html#post5229747), which I thought I had resolved, I was NOT having a problem with this.
But, suddenly, the code for those buttons doesn't seem to be recognizing my AutoFilter status.
I have commented out the code I added, and am trying to roll my code back to when it worked, but I'm still having issues. I think it may stem from my confusion over range and worksheet objects, but I'm not really sure.
I have global variables set to hold the column number for specifically-headed columns (you'll see 'colname' in my code below. That code also
I click my "filter by age" button and run this:
I'm left with filter buttons on my column header row.
Then I click my "Sort by Age" button to run this:
(The Apply in my sort is commented out because it worked a few days ago but now gives an error - I can live without it if the sort is applied, which it seems to be.)
As I said, after clicking the button that filters by age, I have drop-downs indicating a filter in my column header row. But, when I click the Sort button, and debug / step through my code, the wsList.AutofilterMode property is FALSE. But I'm looking at the drop-downs. Is the presence of the drop-downs on my column headers not an indication that AutoFilter is ON?
I have a workbook with multiple sheets that contains my tasks list. I have buttons that perform specific filters and sorts and, up until I tried a few days ago to resolve the problem I describe in another thread (https://www.mrexcel.com/forum/excel...multiple-columns-post5229747.html#post5229747), which I thought I had resolved, I was NOT having a problem with this.
But, suddenly, the code for those buttons doesn't seem to be recognizing my AutoFilter status.
I have commented out the code I added, and am trying to roll my code back to when it worked, but I'm still having issues. I think it may stem from my confusion over range and worksheet objects, but I'm not really sure.
I have global variables set to hold the column number for specifically-headed columns (you'll see 'colname' in my code below. That code also
Code:
Set wb = ThisWorkbookSet wsList = wb.Worksheets("List")
I click my "filter by age" button and run this:
Code:
Public Sub btnAgeRangeFilter_Click()
If Application.EnableEvents = False Then Application.EnableEvents = True
If ColHeaderRow = 0 Then Call globalVars
CurrRow = ActiveCell.Row
CurrCol = ActiveCell.Column
If wsList.AutoFilterMode Then
ColHeaderRow = ColHeaderRow
Else: Cells(ColHeaderRow, 1).AutoFilter
End If
Dim oldest As Integer
Dim newest As Integer
Dim stdt As Date
Dim enddt As Date
oldest = InputBox("Age in days of the oldest to see", "Range of age (startdate) of tasks to see", 1)
newest = InputBox("Age in days of the newest to see", "Range of age (startdate) of tasks to see", 1)
stdt = DateAdd("d", 0 - oldest, Date)
enddt = DateAdd("d", 0 - newest, Date)
With Cells(ColHeaderRow, 1)
.AutoFilter field:=ColStartDate, Criteria1:=">=" & stdt, Criteria2:="<=" & enddt
.AutoFilter field:=ColComplete, Criteria1:="<>C*"
End With
Application.EnableEvents = False
Cells(ColHeaderRow, ColTask).Value = "Filter = between " & stdt & " and " & enddt & " and not complete/canceled" & Chr(10) & "Tasks"
Cells(ColHeaderRow, CurrCol).Activate
ActiveCell.Offset(1).Select
Application.EnableEvents = True
End Sub
I'm left with filter buttons on my column header row.
Then I click my "Sort by Age" button to run this:
Code:
Private Sub btnSortAge_Click()
If ColHeaderRow = 0 Then Call globalVars
Dim vLineCount As Integer
Dim vTaskHdr As Variant
Dim vTaskHdrLen As Integer
If wsList.AutoFilterMode Then
ColHeaderRow = ColHeaderRow
Else: Cells(ColHeaderRow, 1).AutoFilter
End If
CurrRow = ActiveCell.Row
CurrCol = ActiveCell.Column
With wsList.AutoFilter.Sort
.SortFields.Clear
.SortFields.Add Key:=Columns(ColAge), Order:=xlDescending
.SortFields.Add Key:=Columns(ColStartTime), Order:=xlAscending
.SortFields.Add Key:=Columns(ColGoal), Order:=xlAscending
.SortFields.Add Key:=Columns(ColWhen), Order:=xlAscending
.SortFields.Add Key:=Columns(ColPriority), Order:=xlAscending
.Header = xlYes
'.Apply
End With
vTaskHdr = Cells(ColHeaderRow, ColTask).Value
vTaskHdrLen = Len(vTaskHdr)
vLineCount = vTaskHdrLen - Len(Replace(vTaskHdr, Chr(10), "")) + 1
Select Case vLineCount
Case 1: Cells(ColHeaderRow, ColTask).Value = "Sorted by Age" & Chr(10) & "Tasks"
End Select
Cells(CurrRow, CurrCol).Activate
ActiveCell.Offset(1).Select
End Sub
(The Apply in my sort is commented out because it worked a few days ago but now gives an error - I can live without it if the sort is applied, which it seems to be.)
As I said, after clicking the button that filters by age, I have drop-downs indicating a filter in my column header row. But, when I click the Sort button, and debug / step through my code, the wsList.AutofilterMode property is FALSE. But I'm looking at the drop-downs. Is the presence of the drop-downs on my column headers not an indication that AutoFilter is ON?