If you want to work with columns you don't want to use a listbox. Here's a better way. Add a listview and a command button to the form and
Code:Option Explicit Private Sub Command1_Click() Dim lngIndex As Long Dim lngTotal As Long For lngIndex = 1 To ListView1.ListItems.Count - 1 lngTotal = lngTotal + ListView1.ListItems(lngIndex).SubItems(2) Next MsgBox "Average of column3 is " & lngTotal / ListView1.ListItems.Count End Sub Private Sub Form_Load() Dim strParts() As String Dim FF As Integer Dim strLine As String Dim lngIndex As Long Dim bFirst As Boolean ListView1.View = lvwReport FF = FreeFile Open "C:\temp\test.txt" For Input As FF bFirst = True Do While Not EOF(FF) Line Input #FF, strLine strParts = Split(strLine, ",") For lngIndex = 0 To UBound(strParts) If bFirst Then ListView1.ColumnHeaders.Add , , strParts(lngIndex), 500 Else If lngIndex = 0 Then ListView1.ListItems.Add , , strParts(lngIndex) Else ListView1.ListItems(ListView1.ListItems.Count).SubItems(lngIndex) = strParts(lngIndex) End If End If Next bFirst = False Loop Close FF End Sub




Reply With Quote