首页 > 解决方案 > 无法设置列表属性,类型不匹配 - 列表框

问题描述

我正在尝试从工作表中添加一些数据。

该工作表具有来自 SQL 服务器的结果作为记录集我正在尝试将数据提取到用户表单中的列表框有一个列数,因为大多数值即将到来。但很少有单元格在 excel 中具有价值,但在列表框中没有反映

对于那些情况,我正在以下皮棉上

“无法设置列表属性。类型不匹配”

.List(.ListCount - 1, i - 1) = rw.Cells(1, i).Value

Dim lbtarget As MSForms.ListBox
            Dim rngSource As Range
            Dim rw As Range
            Dim i
            Dim lRow
            Dim strng As String
            Dim lCol As Long, lRow1 As Long

           UserForm1.ListBox1.Visible = True

           lRow = Sheets("macro").Range("b" & Rows.Count).End(xlUp).Row

             Set rngSource = Sheets("macro").Range("B15:E" & lRow)
             Set lbtarget = UserForm1.ListBox1

              With lbtarget
                .ColumnCount = 4
                .ColumnWidths = "48;120;220"

                For Each rw In rngSource.Rows
                UserForm1.ListBox1.Visible = True
                    If rw.Cells(1, 1) <> "" Then
                        .AddItem ""
                        For i = 1 To .ColumnCount
                        Dim texdf
                            texdf = rw.Cells(1, i)
                            Debug.Print texdf
                            .List(.ListCount - 1, i - 1) = rw.Cells(1, i).Value

                        Next
                       End If
                Next

            End With
        UserForm1.ListBox1.Visible = True


Else
MsgBox " NO Data Provided, please enter the SEQ_Number", vbOKCancel
End If

标签: excelvbalistboxtype-mismatch

解决方案


推荐阅读