![]() |
Creating an array
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 |
Creating an array
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 |
All times are GMT +1. The time now is 09:43 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com