개선이 필요한 작업 매크로가 있습니다. 매크로의 일부가 Excel 사용자 정의 폼의 목록 상자를 채 웁니다. 코드는 아래와 같다 :Excel 목록 상자의 특정 행을 기본값으로 설정
Dim objExcelApp As Object
Dim objExcelWorkBook As Object
Dim objExcelWorksheet As Object
Dim varTest As Variant
lngLastLitRow = objExcelApp.Sheets(1).UsedRange.Rows.Count
Dim strArray() As Variant
ReDim strArray(lngFilteredRowCount - 1, 2)
'Load strArray
With objExcelWorkBook.Sheets(1)
'The ListBox dimention starts with (0), so set lngListBoxRow
lngListBoxRow = 0
'Loop through all the rows in rngLiturgies
For Each rngCurrentLitRow In rngLiturgies.Rows
'Populate lngExcelRow
lngExcelRow = rngCurrentLitRow.Row
'Select only the rows that are NOT filtered
If rngCurrentLitRow.EntireRow.Hidden = False Then
'Fill the array row (lngListBoxRow) with Excel data (lngExcelRow)
'The Array's column 0 equates to Excel's column 1
strArray(lngListBoxRow, 0) = objExcelWorkBook.Sheets(1).Cells(lngExcelRow, 1)
strArray(lngListBoxRow, 1) = objExcelWorkBook.Sheets(1).Cells(lngExcelRow, 2)
strArray(lngListBoxRow, 2) = objExcelWorkBook.Sheets(1).Cells(lngExcelRow, 3)
'Increment lngListBoxRow "manually" since it doesn't correspond to
'the Excel row in the FOR loop
lngListBoxRow = lngListBoxRow + 1
Else
End If
Next rngCurrentLitRow
End With
'Load ListBoxLit with strArray
With ListBoxLit
.ColumnCount = 3
.List = strArray
End With
인핸스 같이, I가리스트 박스 내의 행 기본하려는마다 다른 형태의 전계 변화 값. 해당 필드 변경을 기반으로 배열의 요소에 해당하는 세 변수의 값을 알 수 있습니다. 이 세 가지 값을 사용할 수있는 경우 목록 상자에서 행을 선택하려면 어떻게해야합니까? 고마워요.
'ListBox.Items'의 각 항목에는'.Selected' 속성 (부울 값)이 있습니다. –
안녕하세요 @DavidZemens, 답장을 보내 주셔서 감사합니다. 어떻게 세 요소의 값을 알고 있는지 ListBoxLit에서 행을 "선택"하는 방법은 무엇입니까? ListBoxLit.selected = ...... – user3138025