SELECT ITEM IN DATA VALIDATION LIST WITH PREVIOUS AND NEXT BUTTON

DeeSt

New Member
Joined
Dec 21, 2020
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
HI, I have a list of item in a data validation which change base on slicers selection, I'll like to select the item in the validation dropdown list with next and previous command button vba.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi, below is the workaround. mylist contains the same items you have in data validation list.

Any reason of using Data Validation? You can add combo box in your sheet and can control effectively using VBA.

VBA Code:
Dim mylist(), itemNo As Integer

VBA Code:
Sub nextItem()
    mylist = Array("Orange", "Apple", "Mango", "Pear", "Peach")
    If Range("A2").validation.Value Then
        For itemNo = 0 To 4
            If ActiveSheet.Range("A2") = mylist(itemNo) And itemNo < 4 Then
                Range("A2") = mylist(itemNo + 1)
                Exit For
            End If
        Next
    End If
End Sub

VBA Code:
Sub previousItem()
    mylist = Array("Orange", "Apple", "Mango", "Pear", "Peach")
    If Range("A2").validation.Value Then
        For itemNo = 0 To 4
            If ActiveSheet.Range("A2") = mylist(itemNo) And itemNo > 0 Then
                Range("A2") = mylist(itemNo - 1)
                Exit For
            End If
        Next
    End If
End Sub
 
Upvote 0
Hi, below is the workaround. mylist contains the same items you have in data validation list.

Any reason of using Data Validation? You can add combo box in your sheet and can control effectively using VBA.

VBA Code:
Dim mylist(), itemNo As Integer

VBA Code:
Sub nextItem()
    mylist = Array("Orange", "Apple", "Mango", "Pear", "Peach")
    If Range("A2").validation.Value Then
        For itemNo = 0 To 4
            If ActiveSheet.Range("A2") = mylist(itemNo) And itemNo < 4 Then
                Range("A2") = mylist(itemNo + 1)
                Exit For
            End If
        Next
    End If
End Sub

VBA Code:
Sub previousItem()
    mylist = Array("Orange", "Apple", "Mango", "Pear", "Peach")
    If Range("A2").validation.Value Then
        For itemNo = 0 To 4
            If ActiveSheet.Range("A2") = mylist(itemNo) And itemNo > 0 Then
                Range("A2") = mylist(itemNo - 1)
                Exit For
            End If
        Next
    End If
End Sub
The data validation is in a cell that is connected to the pivot table list which allow me to search for the item I need the data for and I use the the data validation to select the item if I filter for items so I can select it.
 
Upvote 0
@DeeSt
Could you upload a sample workbook (without sensitive data) to a free site such as dropbox.com or google drive & then share the link here?
It will make it easier to test and find a solution.
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,570
Latest member
rik81h

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