返回首页

如何以表格形式显示的信息列表在启用模式,这样用户可以复制表中的信息。

例如:如果我选择ComboBox1的一个条目,然后相关的信息,从Sheet1的A将显示在表

Sheet1的基础数据如下:

a   xxx-12    pink    xxx-13    yellow

b   xxx-25    black   xxx-01    white

c   xxx-95    red     xxx-58    green

d   xxx-11    cyan    xxx-77    brown

e   xxx-78    blue    xxx-54    orange
如果我选择从ComboBox1的数据,B,C,D和电子邮件,然后把上面的相关信息显示在表的情况下。

谢谢。

回答

评论会员:santhoshkvijayan 时间:2012/02/07
喜遇敌斯里兰卡,
希望这可以帮助你,用
组合框(CBOX)和
列表视图(ListView中)

{C}
[编辑]加入"守则"的标签 - Losmac [/编辑
评论会员:losmac 时间:2012/02/07
至于你想...
Option Explicit 'you must declare variables!



Private Sub CmdFilter_Click()

Dim wsh As Worksheet 'declare object variable of worksheet

Dim i As Integer 'declare integer variable

Dim cmbval As String

 

On Error GoTo Err_CmdFilter_Click 'on error goto error-handler



Set wsh = ThisWorkbook.Worksheets(1) 'set variable



cmbval = Me.ComboBox1.Value

Me.ListBox1.ColumnCount = 5 'set the count of columns



i = 1 'start from row no. 1

Do While wsh.Range("A" & i) <> ""

    If wsh.Range("A" & i) = cmbval Then

        With Me.ListBox1

            .AddItem "" 'add empty string

            .Column(0, .ListCount - 1) = wsh.Range("A" & i) 'column 1, row i

            .Column(1, .ListCount - 1) = wsh.Range("B" & i) 'column 2, row i

            .Column(2, .ListCount - 1) = wsh.Range("C" & i) 'column 3, row i

            .Column(3, .ListCount - 1) = wsh.Range("D" & i) 'column 4, row i

            .Column(4, .ListCount - 1) = wsh.Range("E" & i) 'column 5, row i

        End With

        Exit Do

    End If

    i = i + 1

Loop

 

Exit_CmdFilter_Click:

    On Error Resume Next 'ignore errors

    Set wsh = Nothing 'destroy variable

    Exit Sub

    

Err_CmdFilter_Click:

    MsgBox Err.Description, vbExclamation, Err.Number

    Resume Exit_CmdFilter_Click

End Sub

 

Private Sub UserForm_Initialize()

Dim wsh As Worksheet 'declare object variable of worksheet

Dim i As Integer 'declare integer variable



On Error GoTo Err_UserForm_Initialize 'on error goto error-handler



Set wsh = ThisWorkbook.Worksheets(1) 'set variable



i = 1 'start from row no. 1

Do While wsh.Range("A" & i) <> ""

    Me.ComboBox1.AddItem wsh.Range("A" & i)

    i = i + 1

Loop

 

Exit_UserForm_Initialize:

    On Error Resume Next 'ignore errors

    Set wsh = Nothing 'destroy variable

    Exit Sub

    

Err_UserForm_Initialize:

    MsgBox Err.Description, vbExclamation, Err.Number

    Resume Exit_UserForm_Initialize

End Sub
评论会员:losmac 时间:2012/02/07
这里是一个例子