Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
mct mct is offline
external usenet poster
 
Posts: 4
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a list of value from an array Moanster Excel Worksheet Functions 2 June 20th 07 04:22 PM
creating an array Richard New Users to Excel 4 March 15th 07 01:06 PM
creating an array Richard Excel Worksheet Functions 4 March 15th 07 01:06 PM
Creating Array from Pivot Table WCoaster Excel Worksheet Functions 3 February 27th 06 10:13 PM
Creating an array from non-contiguous ranges David Excel Programming 1 September 16th 03 02:00 PM


All times are GMT +1. The time now is 09:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"