I want to pull all the data from excel sheet and display on listview3. While running below code, I am getting an error 'run time error 13" and 'type mismatch'. Please advise as to what all changes are required.
Dim myFileNameDir As String
Dim wksSource As Worksheet
Dim rngData As Range
Dim rngCell As Range
Dim LstItem As listItem
Dim RowCount As Long
Dim ColCount As Long
Dim I As Long
Dim j As Long
myFileNameDir = Sheet1.Range("V3").Value & TextBox40.Text & ".xlsx"
Workbooks.Open Filename:=myFileNameDir, UpdateLinks:=0
Set wksSource = Worksheets("Sheet1")
Set rngData = wksSource.Range("A1").CurrentRegion
For Each rngCell In rngData.Rows(1).Cells
Me.ListView3.ColumnHeaders.Add Text:=rngCell.Value, Width:=90
Next rngCell
RowCount = rngData.Rows.Count
ColCount = rngData.Columns.Count
For I = 2 To RowCount
Set LstItem = ListView3.ListItems.Add(Text:=rngData(I, 1).Value)
For j = 2 To ColCount
LstItem.ListSubItems.Add Text:=rngData(I, j).Value
Next j
Next I
As I said in my comment
It seems odd that your ListItem is not capitalized in
Dim LstItem As listItem
this might suggest that it's not found the correct reference to the object
As simple first attempt at Debug | Compile
Debug | Compile
will show you that this is not a valid defined type.
If you don't know what the correct object type is you can try Dim LstItem As Object
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.