How to get to the previous value in a column?

Mangolili

Board Regular
Joined
Jun 21, 2011
Messages
54
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
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Sorry, I think I highlighted the wrong section.
This is the part that I think need changes. How do I click on the button and it will show the value before instead of the next value. Any help would be appreciated. Thanks.

Code:
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)                         I
f 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
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top