如何使用VBA将标题添加到Excel用户窗体中的多列列表框中 [英] How to add headers to a multicolumn listbox in an Excel userform using VBA

查看:1466
本文介绍了如何使用VBA将标题添加到Excel用户窗体中的多列列表框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在多列列表框中设置标题,而不使用工作表范围作为源?

Is it possible to set up the headers in a multicolumn listbox without using a worksheet range as the source?

以下使用一组变量,分配给列表框的列表属性,标题显示为空白。

The following uses an array of variants which is assigned to the list property of the listbox, the headers appear blank.

Sub testMultiColumnLb()
    ReDim arr(1 To 3, 1 To 2)

    arr(1, 1) = "1"
    arr(1, 2) = "One"
    arr(2, 1) = "2"
    arr(2, 2) = "Two"
    arr(3, 1) = "3"
    arr(3, 2) = "Three"


    With ufTestUserForm.lbTest
        .Clear
        .ColumnCount = 2
        .List = arr
    End With

    ufTestUserForm.Show 1
End Sub


推荐答案

我在列表框上方创建标签作为标题。您可能会认为,每当您的lisbox发生变化时,更改标签是一种皇室痛苦。你是对的 - 这是一个痛苦。第一次设置是一个痛苦,更少的变化。但我没有找到更好的方法。

No. I create labels above the listbox to serve as headers. You might think that it's a royal pain to change labels every time your lisbox changes. You'd be right - it is a pain. It's a pain to set up the first time, much less changes. But I haven't found a better way.

这篇关于如何使用VBA将标题添加到Excel用户窗体中的多列列表框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆