copying data from text file to excel sheet

S

sreedhar

hi

i want to copy data from text file to excel sheet

for ex

the data int the text file is

1 0 1 0 1
0 1 0 1 0
1 0 1 0 1

we have get this data into excel sheet like this

A B C D E
1 1 0 1 0 1
2 0 1 0 1 0
3 1 0 1 0 1
4
5


So,Plz help me regarding this

thanks
sree
 
T

Tom Ogilvy

turn on the macro recorder and then do file=>OPen and select your file. go
through the text import wizard and select delimited and space as the
delimiter (or tab - whatever is appropriate).

Then, when the file is in, turn off the macro recorder.

This gives you the basic code you need.

If you want it in an existing sheet, then just use additional code like

Activesheet.UsedRange.copy Destination:= _
ThisWorkbook.worksheets(1).Range("A1")
ActiveWorkbook.Close Savechanges:=False

You can also modify the code to allow you to select a file by using

fName = Application.GetOpenfileName

then replacing the hard coded filename in the recorded code with fname
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top