Список не отображает значения, которые были заполнены в нем с помощью метода Listbox.List - PullRequest
0 голосов
/ 20 ноября 2018

После запуска события Userform_Initialize() в списке ничего не будет заполнено, как показано ниже:

enter image description here

Должно быть 11 столбцов, заполняющих список на основе таблицы Excel ниже:

enter image description here

Код побежал:

Private Sub UserForm_Initialize()

Dim Total_rows_FoilProfile As Long
Dim row As Range, i As Long

Total_rows_FoilProfile = TotalRowsCount(ThisWorkbook.Name, "Foil Profile", "tblFoilProfile")

ReDim MyArr(0 To Total_rows_FoilProfile - 1)

For Each row In ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").Range.SpecialCells(xlCellTypeVisible).Rows
    MyArr(i) = row.Value
    i = i + 1
Next row

lbxFoilInfoDisplay.List = MyArr

frmFoilPanel.Show

Свойства списка:

enter image description here

enter image description here

1 Ответ

0 голосов
/ 20 ноября 2018

Вы можете заполнить каждую строку списка и затем добавить к ней столбцы:

Option Explicit

Private Sub UserForm_Initialize()
    Dim tblFoilProfile As ListObject
    Set tblFoilProfile = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile")

    Dim i As Long

    lbxFoilInfoDisplay.Clear

    Dim iListRow As Range
    For Each iListRow In tblFoilProfile.DataBodyRange.SpecialCells(xlCellTypeVisible).Rows
        With Me.lbxFoilInfoDisplay
            .AddItem iListRow.Cells(1, 1).Value 'add first value (column 1)

            Dim iCol As Long
            For iCol = 2 To iListRow.Columns.Count 'add all other columns to that row
                .list(i, iCol) = iListRow.Cells(1, iCol).Value '.Value for unformatted value or .Text to show it in the same format as in the cell
            Next iCol
            i = i + 1
        End With
    Next iListRow
End Sub

Обратите внимание, что хорошее руководство по работе со списком объектов .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...