我在Excel 2007中的userform中有一个列表框。
我的工作表中的某些单元格包含10行以上(ALT ENTER数据)。
我正在尝试清理和显示数据。我不想将列宽更改为1000,但我想使用鼠标悬停框来显示所有单元格数据。
还有其他想法可行吗?
答案 0 :(得分:1)
鼠标悬停可以做到,但我认为这很复杂。在这里,我有另一个更简单的想法:在列表框中双击一个包含所选列表项数据的多行文本框。此文本框与列表框具有相同的位置和大小。在用户表单上单击文本框隐藏。下面是一些示例代码,为了测试它,您需要具有名为" ListBox1"的列表框的表单:
Option Explicit
Public ListItemInfo As Control
Private Sub UserForm_Initialize()
Set ListItemInfo = Me.Controls.Add("Forms.TextBox.1", "ListItemInfo", False)
With Me.ListItemInfo
.Top = Me.ListBox1.Top
.Left = Me.ListBox1.Left
.Width = Me.ListBox1.Width
.Height = Me.ListBox1.Height
.MultiLine = True
End With
End Sub
Private Sub ListBox1_Change()
Me.ListItemInfo.text = GetSelectedItemsText
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
SwitchListItemInfo
End Sub
Private Sub UserForm_Click()
SwitchListItemInfo
End Sub
Private Function GetSelectedItemsText() As String
Dim text As String
Dim i As Integer
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) Then
text = text & Me.ListBox1.List(i) & vbNewLine
End If
Next i
GetSelectedItemsText = text
End Function
Private Sub SwitchListItemInfo()
If Me.ListItemInfo.text = "" Then Exit Sub
Me.ListItemInfo.Visible = Not Me.ListItemInfo.Visible
Me.ListBox1.Visible = Not Me.ListBox1.Visible
End Sub