Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

/b Text to excel format

Status
Not open for further replies.

Terence

Technical User
Feb 22, 2001
30
US
HI All, i am using this code to get text from a file . It works fine on small files. I am trying to read files that are 4400 lines long on average. What happens is once in while this will pickup two strings at the same time and will format the first string but will add the next line on the end of it.
As you can see i am putting this into an excel workbook which works fine and i get the same result if i use the debug window.

I haven't been able to get around this any help would be appreciated.

Open getfile For Input As fnum1

strData = Input(LOF(fnum1), fnum1)
StrLineItems() = Split(strData, vbCrLf)
Lower = LBound(StrLineItems)
Upper = UBound(StrLineItems)

Open formatfile For Output Shared As fnum2

z = 0

For i = Lower To Upper

strOut = Mid(StrLineItems(i), 3, 11) _
& Space(4) _
& Mid(StrLineItems(i), 14, 10) _
& Space(4) _
& Mid(StrLineItems(i), 23)

z = z + 1

objExcel.Activecell.Offset(z, 0) = strOut

X-)
 
So it looks like it's concantinating the next cell's value to the end of the previous cell? You can try separating the cells with the vbTab character:

-------------------------------------
strOut = Mid(StrLineItems(i), 3, 11) _
& Space(4) _
& Mid(StrLineItems(i), 14, 10) _
& Space(4) _
& Mid(StrLineItems(i), 23 _
& vbTab 'Added this line
-------------------------------------

It looks like you're handling the cells in code via the for loop, but I think this is how Excel handles separations between cells. Just a thought, it may be worth a try...

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
thanks for the try Mike, but for the most part the strings do seperate them selves into there own line when exported to excel. The concetantion happens about 10 lines down for one string and then it carriers on as normal till about 600 lines and so on.
I am running this on a 266 PII ,just wondering if there may be a memory block or something like that......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top