The following code is for capturing the autofilter setting and read next value in a column when i click the button. I wonder what I can do to make it show the previous value when the button is clicked. Please help thank you.
Code:
'Capture AutoFilter settings
With WS.AutoFilter
currentFiltRange = .Range.Address
With .Filters
intColCount = .Count
ReDim filterArray(1 To intColCount, 1)
For i = 1 To intColCount
With .Item(i)
If .On Then
filterArray(i, 1) = .Criteria1
If .Operator Then
MsgBox "Only one filter per column please."
Exit Sub
End If
' debug
' MsgBox filterArray(i, 1)
End If
End With
Next i
intColCount = .Count
[B] For i = 1 To intColCount
If filterArray(i, 1) <> "" Then
'Paste distinct column values onto Values tab
'************************ changed the range
WS.Range("A" & i & ":A" & Range("A" & _
i).End(xlDown).Row).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Sheets("Value").Range("A1"), Unique:=True
End If
'***********************sort data alpha
With Sheets("Value")
.Range("A1", .Range("A" & Rows.Count).End(xlUp)).Sort _
Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
Next i
[/B]
' This Sub reads the filters from "Value" sheet and store them in
' availableFilters array and deletes the sheet "Value"
ReadAvailableFilters
For i = 1 To intColCount
If filterArray(i, 1) <> "" Then
'Assign new filter value
'loop through the distinct value array
'find where filterarray = value array
'assign next value to column
For x = 1 To UBound(availableFilters)
If availableFilters(x) = Replace(filterArray(i, 1), "=", "") Then
Range(currentFiltRange).AutoFilter field:=i, Criteria1:=availableFilters(x + 1)
End If
Next
End If
Next
End With
End With
End Sub