Could one of you experts answer an easy question...

  • Thread starter Thread starter Bryan
  • Start date Start date
B

Bryan

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
 
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
 
How are you importing your dataset?

Have you tried using

Application.Transpose(rs)
 
Back
Top