【问题标题】:Too much data in a cell to display in a Userform Listbox单元格中的数据过多,无法在用户表单列表框中显示
【发布时间】:2013-03-08 15:29:44
【问题描述】:

我在 Excel 2007 的用户窗体中有一个列表框。

我的工作表中的某些单元格包含超过 10 行(带有 ALT ENTER 的数据)。

我正在尝试清理和显示数据。我不想将列宽更改为 1000,但我想使用鼠标悬停框来显示所有单元格数据。

还有其他可行的方法吗?

【问题讨论】:

  • 您是要在工作表中还是在表单中显示数据?我不明白你在问什么。如果您的表单/列表框并不重要,并且您只想通过某种方式查看工作表中的所有行,那么就这么说吧。否则你能详细说明一下吗。
  • 我的工作表视图不重要,我的表单很重要。我希望它在我的表单上的列表框中显示干净。最好用鼠标悬停和一个小工具箱。但我找不到任何做过或尝试过这个的人。
  • 具有多行的单元格,单元格中的每一行是否代表列表中的一项?还是将整个单元格值放入单个列表项中。你能提供一些截图吗? (使用链接更新您的问题)

标签: excel vba userform


【解决方案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

【讨论】:

  • 不客气。如果你喜欢这个答案,请点赞。我会很高兴得到一些分数:-)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-18
相关资源
最近更新 更多