Excel 列表框选择变为文本框选择
我希望用户能够从列表框中单击一个值,并将所选值变为文本框值。我从Excel 列表框选择变为文本框选择,excel,vba,userform,Excel,Vba,Userform,我希望用户能够从列表框中单击一个值,并将所选值变为文本框值。我从Textbox1.Value=selectedItems.Text中得到一个编译错误:selectedItems的限定符无效。我希望选定的值也显示在文本框中 Private Sub ListBox1_Click() Dim selectedItems As String, i As Integer For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected
Textbox1.Value=selectedItems.Text中得到一个编译错误:selectedItems
的限定符无效。我希望选定的值也显示在文本框中
Private Sub ListBox1_Click()
Dim selectedItems As String, i As Integer
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
selectedItems = selectedItems & ListBox1.List(i) & vbNewLine
End If
Next i
TextBox1.Value = selectedItems.Text
End Sub
selectedItems
是一个字符串,字符串没有任何属性,例如Text
TextBox1.Value = selectedItems
将是您需要的它是多行文本框吗?默认情况下不会。我删除了我的注释,因为我可以添加myString=Left(myString,Len(myString)-1)
删除段落符号如果您只选择了一个ListBox
项,则您当前的代码不正确,问题中的代码用于将列表框1
中的多个选定项添加到文本框中的当前文本中。您不需要遍历每个列表框1
项。如果要将单击的项目从ListBox1
放入TextBox1
中,则只需TextBox1.Text=ListBox1
所有其他代码都多余。