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.
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
413
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
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
 

DeeSt

New Member
Joined
Dec 21, 2020
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
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.
 

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,958
Office Version
  1. 365
Platform
  1. Windows
@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.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,100
Messages
5,622,725
Members
415,924
Latest member
togo

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
Top