I am trying to get it working so that I can have a list with duplicate prevention but at the same time have it where a data validation drop down list can be used. Any help appreciated
I've created a simple example below which works perfectly for manual entry of what I'm trying to achieve:
Example:
Visible
[TABLE="width: 397"]
A
[/td]B
[/td]C
[/td]1
[/td]Ford
[/td]Mondeo
[/td]FordMondeo
[/td]2
[/td]Ford
[/td]Focus
[/td]FordFocus
[/td]3
[/td]Vauxhall
[/td]Astra
[/td]VauxhallAstra
[/td]4
[/td]Renault
[/td]Megane
[/td]RenaultMegane
[/td]5
[/td]Renault
[/td]Clio
[/td]RenaultClio
[/td]6
[/td]Ford
[/td]Focus
[/td]FordFocus
[/td]
[/TABLE]
Ford is a none permitted entry in A6 due to the validation formula.
Same code showing data validation present in column A and cell formula in column C
[TABLE="width: 434"]
A Cells containing Data validation custom formula
[/td]Cell formula
[/td]A
[/td]B
[/td]C
[/td]1
[/td]=COUNTIF(C:C,C1)=1
[/td]Mondeo
[/td]=A1&B1
[/td]2
[/td]=COUNTIF(C:C,C2)=1
[/td]Focus
[/td]=A2&B2
[/td]3
[/td]=COUNTIF(C:C,C3)=1
[/td]Astra
[/td]=A3&B3
[/td]4
[/td]=COUNTIF(C:C,C4)=1
[/td]Megane
[/td]=A4&B4
[/td]5
[/td]=COUNTIF(C:C,C5)=1
[/td]Clio
[/td]=A5&B5
[/td]6
[/td]=COUNTIF(C:C,C6)=1
[/td]Focus
[/td]=A6&B6
[/td]
[/TABLE]
What I wanted to do is have it so that the custom data validation formula used in column A is instead in VBA. Then 'Column A' should instead contain a drop down list using the Data Validation List allowing for selecting an option e.g. Ford, Vauxhall, Renault, . I already have an extensive set of drop down lists using indirect vlookups, so implementing the list selection drop down another way to do a list would not be ideal.
I found a previous post which does something similar to what I'm looking for (http://www.ozgrid.com/forum/showthread.php?t=157244) but I think it needs the variable 'r' to carry the value to the formula like what I have in column C but when a change occurs in column A and then preventing entry to the Cell in column A.
In my finished spreadsheet the solution also needs to be able to co-exist with another macro effecting the same cells which clears the values of other drop downs when primary ones are changed:
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Column = 6 Then
Application.EnableEvents = 0
.Cells.Offset(, 1).ClearContents
.Cells.Offset(, 2).ClearContents
.Cells.Offset(, 3).ClearContents
.Cells.Offset(, 4).ClearContents
.Cells.Offset(, 5).ClearContents
.Cells.Offset(, 6).ClearContents
.Cells.Offset(, 7).ClearContents
Application.EnableEvents = 1
End If: End With
With Target
If .Column = 7 Then
Application.EnableEvents = 0
.Cells.Offset(, 6).ClearContents
Application.EnableEvents = 1
End If: End With
End Sub
Display More