运行时错误13使用字母数字数据在组合框中键入不匹配
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运行时错误13使用字母数字数据在组合框中键入不匹配相关的知识,希望对你有一定的参考价值。
我正在尝试设置更新数据输入表单。如何使用字符串或带有字母数字值的长组合框从仅包含数值的整数组合框转换为数据类型?
Private Sub UserForm_Activate()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Employee Details")
Dim i As Integer
Me.UsernameComboBox.Clear
Me.UsernameComboBox.AddItem ""
For i = 11 To sh.Range("B" & Application.Rows.Count).End(xlUp).Row
Me.UsernameComboBox.AddItem sh.Range("B" & i).Value
Next i
End Sub
Private Sub UsernameComboBox_Change()
If Me.UsernameComboBox <> "" Then
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Employee Details")
Dim i As Integer
i = Application.Match(VBA.CLng(Me.UsernameComboBox.Value), sh.Range("B:B"), 0)
Me.NameTextBox = sh.Range("A" & i).Value
Me.EmailTextBox = sh.Range("C" & i).Value
Me.BirthdateTextBox = sh.Range("D" & i).Value
Me.NationalIDTextBox = sh.Range("E" & i).Value
Me.EmpIDTextBox = sh.Range("R" & i).Value
Me.DeptTextBox = sh.Range("V" & i).Value
If sh.Range("Y" & i).Value = "Male" Then Me.MaleOptionButton.Value = True
If sh.Range("Y" & i).Value = "Female" Then Me.FemaleOptionButton.Value = True
Me.StatusComboBox = sh.Range("X" & i).Value
Me.CitizenshipComboBox = sh.Range("Z" & i).Value
Me.EthnicityComboBox = sh.Range("F" & i).Value
End If
End Sub
答案
欢迎来到SO。假设您确实不想将B列中的数值更改为Text或使用公式为=Text(B11,"#")
的其他列,则可能很容易使用变通方法Find
。可以试试
Dim i As Integer
Dim FndRng As Range, c As Range
'i = Application.Match(Me.UsernameComboBox.Value, Sh.Range("B:B"), 0)
Set FndRng = Sh.Range("B11:B" & Sh.Range("B" & Application.Rows.Count).End(xlUp).Row)
Set c = FndRng.Find(Me.UsernameComboBox.Value, , LookIn:=xlValues)
If Not c Is Nothing Then
i = c.Row
Else
MsgBox "Not found"
Exit Sub
End If
以上是关于运行时错误13使用字母数字数据在组合框中键入不匹配的主要内容,如果未能解决你的问题,请参考以下文章
在组合框中使用向下/向上箭头键选择数据而不更新数据,直到点击选项卡或输入 MS Access