Copy data from .txt to .xls

R

rea

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
 
D

dolivastro

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
 

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