ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Could one of you experts answer an easy question... (https://www.excelbanter.com/excel-programming/276484-could-one-you-experts-answer-easy-question.html)

Bryan[_5_]

Could one of you experts answer an easy question...
 
Hi guys--

Simple problem for you. I've imported a dataset into Excel
where each record consists of n variables, but instead of
each record's variables being distributed into columns of
the same row (what I want), they are all in column A on
different rows.

That is, rows 1 through n comprise record 1, rows n+1
through 2n comprise record 2, etc. (Everything is in the
same column, and there are a total of (number of variables
per record)*(number of records) rows.

I'd like to take the values in rows 1 through n and put
them into columns A through (n.th letter) in row 1 thus
creating a normal single record. Ditto for the rest of the
dataset, rows n+1 through 2n into columns A through (n.th
letter) in row 2.

I'll thank you guys in advance since you've always come up
with a solution to my problems :)

Bryan

Jim Rech

Could one of you experts answer an easy question...
 
Select your sata in column A, and run this macro. Be sure to adjust
RowsPerRec to your row count per record.

Const RowsPerRec As Integer = 6

Sub a()
Dim SrcRg As Range
Dim Cell As Range, ColNum As Integer
Dim Counter As Long
Application.ScreenUpdating = False
Set SrcRg = Selection
Worksheets.Add
For Each Cell In SrcRg
Cells(Int(Counter / RowsPerRec) + 1, (Counter Mod RowsPerRec + 1)).Value
= Cell.Value
Counter = Counter + 1
Next
End Sub


--
Jim Rech
Excel MVP



Tom Ogilvy

Could one of you experts answer an easy question...
 
How are you importing your dataset?

Have you tried using

Application.Transpose(rs)


--
Regards,
Tom Ogilvy


"Bryan" wrote in message
...
Hi guys--

Simple problem for you. I've imported a dataset into Excel
where each record consists of n variables, but instead of
each record's variables being distributed into columns of
the same row (what I want), they are all in column A on
different rows.

That is, rows 1 through n comprise record 1, rows n+1
through 2n comprise record 2, etc. (Everything is in the
same column, and there are a total of (number of variables
per record)*(number of records) rows.

I'd like to take the values in rows 1 through n and put
them into columns A through (n.th letter) in row 1 thus
creating a normal single record. Ditto for the rest of the
dataset, rows n+1 through 2n into columns A through (n.th
letter) in row 2.

I'll thank you guys in advance since you've always come up
with a solution to my problems :)

Bryan





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com