我的单元格有数据验证下拉列表。
如何检索当前选定的值?
例如,有以下情况:1)cat 2)dog 3)hyp下拉列表中的当前狗被选中,我需要一个代码来获得" dog"价值,当选择其他东西时,我会得到它的价值。
我已尝试cells(1,1).value range("A1").value
等,但没有工作。
代码如下:
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
答案 0 :(得分:0)
这是函数的代码:
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)