Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 从数据列表中获取所选值_Vba_Validation_Excel - Fatal编程技术网

Vba 从数据列表中获取所选值

Vba 从数据列表中获取所选值,vba,validation,excel,Vba,Validation,Excel,我有一个单元格,其中有数据验证下拉列表 如何检索其中当前选定的值 例如,下拉列表中有:1)cat 2)dog 3)hypo,当前已选择dog,我需要一个代码来获取“dog”值,当选择其他内容时,我将获取其值 我尝试了单元格(1,1)。值范围(“A1”)。值等无效 代码类似于: Private Function Kne_mida_calc() As Double If Range("E16").Validation.Formula1 = "1:250" Then Kne_m

我有一个单元格,其中有数据验证下拉列表

如何检索其中当前选定的值

例如,下拉列表中有:1)cat 2)dog 3)hypo,当前已选择dog,我需要一个代码来获取“dog”值,当选择其他内容时,我将获取其值

我尝试了
单元格(1,1)。值范围(“A1”)。值
等无效

代码类似于:

 Private Function Kne_mida_calc() As Double
   If Range("E16").Validation.Formula1 = "1:250" Then
        Kne_mida_calc = 1.3
        Exit Function
    ElseIf Cells(15, 5).Value = "1:500" Then
        Kne_mida_calc = 1.15
        Exit Function
        ElseIf Cells(15, 5).Value = "1:1250" Then
        Kne_mida_calc = 1
        Exit Function
     ElseIf Cells(15, 5).Value = "1:2500" Then
        Kne_mida_calc = 0.85
        Exit Function
    ElseIf Cells(15, 5).Value = "1:5000" Then
        Kne_mida_calc = 0.75
        Exit Function
    ElseIf Cells(15, 5).Value = "1:10000" Then
        Kne_mida_calc = 0.5
        Exit Function
    End If
End Function

这是函数的代码:


Private Function Kne_mida_calc(scl As String)  
Select Case scl  
    Case "1:250"  
        Kne_mida_calc = 1.3  
        Exit Function  
    Case "1:500"  
        Kne_mida_calc = 1.15  
        Exit Function  
    Case "1:1250"  
        Kne_mida_calc = 1  
        Exit Function  
    Case "1:2500"  
        Kne_mida_calc = 0.85  
        Exit Function  
    Case "1:5000"  
        Kne_mida_calc = 0.75  
        Exit Function  
    Case "1:10000"  
        Kne_mida_calc = 0.5  
        Exit Function  
    Case Else  
        Kne_mida_calc = "Error!"  
        Exit Function  
End Select  
End Function  
如何在工作表中使用函数:
将数据验证放在单元格E16中

将此公式放入另一个单元格:

=Kne_mida_calc(E16)

@A.S.H我已经发布了我尝试做的事情,使用两个不同的选项尝试使用.Text而不是.Value,只是为了看看?我已经尝试过,我想我会尝试使用Com-Ins下拉列表而不是数据验证工具,因为我没有找到与Value或Text属性对应的验证对象属性…:\让我困惑的是,您如何在验证范围内输入1:500、1:1500等?它是否真的将其显示为字符串?还是将它转换成一个数字?我几乎可以肯定,问题在于这些值的特殊形状。1:500,这是不寻常的,Excel会将其转换为数字,除非将单元格类型设置为文本。