LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How to Impot data from a text file to another worksheet.

I have used the following code, which I found here. I am sorry I do not remember who the originator was, but the code works great except that I am having problems getting it to write to another worksheet

I need this macro to work in the background and copy the data from a text file to the worksheet "Names". The worksheet "Names" is hidden

I tried the following but it does not work. It will only copy the data onto the active worksheet

Public Sub ImportTextFile(FName As String, Sep As String

Dim RowNdx As Intege
Dim ColNdx As Intege
Dim TempVal As Varian
Dim WholeLine As Strin
Dim Pos As Intege
Dim NextPos As Intege
Dim SaveColNdx As Intege

Application.ScreenUpdating = Fals
'On Error GoTo EndMacro

SaveColNdx = Worksheets("Names").Range("A1").Colum
'SaveColNdx = ActiveCell.Column '<<< Original Cod
RowNdx = Worksheets("Names").Range("A1").Ro
'RowNdx = ActiveCell.Row '<<< Original Cod

Open FName For Input Access Read As #

While Not EOF(1
Line Input #1, WholeLin
If Right(WholeLine, 1) < Sep The
WholeLine = WholeLine & Se
End I
ColNdx = SaveColNd
Pos =
NextPos = InStr(Pos, WholeLine, Sep
While NextPos =
TempVal = Mid(WholeLine, Pos, NextPos - Pos
Cells(RowNdx, ColNdx).Value = TempVa
Pos = NextPos +
ColNdx = ColNdx +
NextPos = InStr(Pos, WholeLine, Sep
Wen
RowNdx = RowNdx +
Wen

EndMacro
On Error GoTo
Application.ScreenUpdating = Tru
Close #

End Su

Any help will be very welcome. Thanks.
 
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
How do a import data from a text file to an excel worksheet madlin Excel Discussion (Misc queries) 4 January 12th 10 04:04 PM
text file contains more data than will fit for a single worksheet Ray Excel Discussion (Misc queries) 1 May 11th 09 05:54 PM
importing text file, removing data and outputting new text file Pal Excel Programming 8 February 27th 04 08:32 PM
Open delimited text file to excel without changing data in that file zohanc Excel Programming 1 October 3rd 03 01:06 AM
Get External Data, Import Text File, File name problem Scott Riddle Excel Programming 1 July 11th 03 05:40 PM


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

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

About Us

"It's about Microsoft Excel"