|
Complete Excel Excel Training Course. Instant Buy/Download, 30 Day Money Back Guarantee FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE.. |
Got any Excel Questions? Free Excel Help
See Also: Stop/Prevent Duplicates in Excel || Stop/Prevent Blanks in Excel || Dependent Validation Lists
Decreasing Data Validation Lists
If you need to have a list of options that decreases as users select from it, you can use Data Validation and some Excel VBA Code .
On any Worksheet add your list, say in A1:A10. Now select this range and click in the Name Box (left of the Formula bar), type the name: MyList and then Enter. This will give you a Named Range called MyList
Now select the range on another Worksheet where you would like the Validation Lists to go. Now right click on this sheet name tab, select View Code and paste in the code below;
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strVal As String
Dim strEntry As String
On Error Resume Next
strVal = Target.Validation.Formula1
If Not strVal = vbNullString Then
strEntry = Target
Application.EnableEvents = False
With Sheet1.Range("MyList")
.Replace What:=strEntry, _
Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False
.Sort Key1:=.Range("A1"), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
.Range("A1", .Range("A65536").End(xlUp)).Name = "MyList"
End With
End If
Application.EnableEvents = True
On Error GoTo 0
End Sub
You should note that I have referred to the named range MyList as Sheet1.("MyList"). I have preceded the named range with its Sheet CodeName . The reason for this is that the reference to the named range (MyList) is in the Private Module of another Worksheet. Without it, Excel would assume MyList is on the same Worksheet as the Worksheet_Change code resides
Excel Dashboard Reports & Excel Dashboard Charts 50% Off
Special! Free Choice of Complete Excel Training Course OR Excel Add-ins Collection on all purchases totaling over $64.00. ALL purchases totaling over $150.00 gets you BOTH! Purchases MUST be made via this site. Send payment proof to special@ozgrid.com 31 days after purchase date.
Instant Download and Money Back Guarantee on Most Software
Excel Trader Package Technical Analysis in Excel With $139.00 of FREE software!
Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft