Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I am trying to create a macro that store my text file data into an array and open it in excel file. My text file data looks like this: Column1 Column2 Row1 Name1 TextLength1 Row2 Name2 TextLength2 Row3 Name3 TextLength3 . . . . . . . . . Assuming rows is unlimited, How could I store this data into an array? I would appreciate anyone's input, tips or suggestions. Regards Eric |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
But why in an Array? I think it's easier to read the data from the text
file, and pump it straight into the worksheet. Like this. Option Explicit Public Sub LoadTextFileData() Dim wb As Workbook Dim ws As Worksheet Dim txtFile As String Dim fileLineTxt As String Dim fileLineLen As Integer Dim rowNum As Integer Dim colNum As Integer Set wb = ThisWorkbook Set ws = wb.Sheets("Sheet1") txtFile = "C:\textfile.txt" rowNum = 1 colNum = 1 With ws Open txtFile For Input As #1 Do While Not EOF(1) Line Input #1, fileLineTxt fileLineLen = Len(fileLineTxt) If fileLineTxt < "" Then ws.Cells(rowNum, colNum).Value = fileLineTxt ws.Cells(rowNum, (colNum + 1)).Value = fileLineLen End If rowNum = rowNum + 1 Loop Close #1 End With End Sub *Filling an array can be done in the IF-statement. Hans "Eric" schreef in bericht ... Hi, I am trying to create a macro that store my text file data into an array and open it in excel file. My text file data looks like this: Column1 Column2 Row1 Name1 TextLength1 Row2 Name2 TextLength2 Row3 Name3 TextLength3 . . . . . . . . . Assuming rows is unlimited, How could I store this data into an array? I would appreciate anyone's input, tips or suggestions. Regards Eric |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Creating a list of value from an array | Excel Worksheet Functions | |||
creating an array | New Users to Excel | |||
creating an array | Excel Worksheet Functions | |||
Creating Array from Pivot Table | Excel Worksheet Functions | |||
Creating an array from non-contiguous ranges | Excel Programming |