PC Review


Reply
Thread Tools Rate Thread

Copy data from .txt to .xls

 
 
rea
Guest
Posts: n/a
 
      16th Oct 2006
Problem:I have a .txt which contains 100 rows (each row is only one
word or number).
I managed to copy all 100 values into .xls (all 100 data in one
column).but i need to split those 100 values into 5 colums (each column
would contain 20 values).
like this: .txt
1
2
3
4
5
6
..
..
..
100

..xls would look like this:
1 21 41
2 22 42
3 23 .
4 . .
.. . .
.. . .
20 40 60 and so on, till 100.
please could somebody help me

 
Reply With Quote
 
 
 
 
dolivastro@gmail.com
Guest
Posts: n/a
 
      16th Oct 2006
Well, you can easily do that with your mouse, but since you are posting
in a "programming" news group, I assume you need a VBA solution. Here
is one, but it is untested. This will copy original data from column A
to columns B ... F

----------------------------------------
public sub Copy_alll

dim s As Excel.Worksheet

set s = activesheet

call Copy_Section (s, 1, 20, "B")
call Copy_Section (s, 21, 40, "C")
call Copy_Section (s, 41, 60, "D")
call Copy_Section (s, 61, 80, "E")
call Copy_Section (s, 81, 100, "F")
end sub



private sub Copy_Section (s as Excel.Worksheet, fRow as Long, lRow as
long, Col as String)

dim x as long
dim r as long

x = 0
for r = fRow to lRow
x = x + 1
s.Cells (x, Col).value = s.Cells (r, "A").value
next r
end sub


rea wrote:
> Problem:I have a .txt which contains 100 rows (each row is only one
> word or number).
> I managed to copy all 100 values into .xls (all 100 data in one
> column).but i need to split those 100 values into 5 colums (each column
> would contain 20 values).
> like this: .txt
> 1
> 2
> 3
> 4
> 5
> 6
> .
> .
> .
> 100
>
> .xls would look like this:
> 1 21 41
> 2 22 42
> 3 23 .
> 4 . .
> . . .
> . . .
> 20 40 60 and so on, till 100.
> please could somebody help me


 
Reply With Quote
 
rea
Guest
Posts: n/a
 
      16th Oct 2006

thnx, i will try it and let you know does it works!!!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use data fed in adjacent cells to sort and copy the data to spec named range sri_gs Microsoft Excel Discussion 0 12th Apr 2010 02:07 PM
Pivot Table - Copy All Data from a Specific Variable Data Field troy.litwiler@gmail.com Microsoft Excel Discussion 1 8th Feb 2007 04:36 AM
Copy function does not copy data in subforms =?Utf-8?B?Q1c=?= Microsoft Access Forms 2 17th Nov 2006 02:25 PM
Copy data into cells until changes trigger new copy =?Utf-8?B?bWRlYW5kYQ==?= Microsoft Excel Programming 1 25th Apr 2005 05:40 AM
Copy Child DataTable?? Copy a DataColumn?? System.Data is frustrating... Cip Microsoft ADO .NET 1 27th Feb 2004 05:57 AM


Features
 

Advertising
 

Newsgroups
 


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