Data Validation Question - List or any value

zherczku

New Member
Joined
Dec 28, 2004
Messages
11
Hi All,

I try to make a data validation that depeing on the adjacent cell value allows to select from a drop down list (in case of "Employee") or allows to enter any value into the cell (in case of "External").

I tried to use the following formula =indirect(if($A2="Employee"; "NamedRange_Employee" ; "")). It works fine if Employee is selected, but does not work in the other case. The Indirect("") does not allow the "any value selection".


Any suggestion, solution? This should be a simple task, but I was not able to find how to solve...

Thanks,

Zoli
 
Paste this into Sheet1. Remember to test on a copy of your Workbook as unexpected results may occur.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim wb As Workbook, ws1 As Worksheet, ws2 As Worksheet
Set wb = ThisWorkbook
Set ws1 = wb.ActiveSheet
Set ws2 = wb.Sheets("Employee")

If Left(Target.Address, 2) = "$B" Then
    If Target.Offset(0, -1).Value = "Employee" Then
        With Target
            .Validation.Delete
            .Validation.Add xlValidateList, Formula1:="=Employee!$AA$1:$AA$49"
        End With
    Else
        With Target
            .Validation.Delete
        End With
    End If
Else
    Exit Sub
End If
End Sub
Thanks a lot Skyybot !!!!

Based on this I could complete the task, here is my code:

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim sv As String

    Dim tblcol As ListColumn

    Set wb = ThisWorkbook
    Set ws = wb.ActiveSheet
    Set tblcol = ThisWorkbook.Worksheets("Project Resource").ListObjects("DB_ProjectResource").ListColumns("Name")

    If Intersect(Target, tblcol.DataBodyRange) Is Nothing Or Target.Count <> 1 Then
        Exit Sub
    Else
  
        If Target.Offset(0, -2).Value = "Vodafone" Then
            With Target
                sv = "=INDIRECT(""BL_Compl"")"
                .Validation.Delete
                .Validation.Add xlValidateList, Formula1:=sv
            End With
        Else
            Target.Validation.Delete
        End If
    End If
End Sub
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,093
Messages
6,123,067
Members
449,090
Latest member
fragment

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