LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Converting a grid of data to linear

Hi Patrick, Joel and R

Thanks for all the instant help. All three solutions work for me, if I do a
couple of minor tweaks.

I hope you all know how much I appreciate your help!

Regards

Charles

"r" wrote:



"Charles" wrote:

I need to transpose a grid of data into a linear format, a cut of the
existing data looks like this:

B C D E
1 35714.57 0 0 34365.98
2 23874.54 0 23843.06 22860.84
3 44657.62 0 0 42872.15
4 33940.83 0 0 33940.83
5 52097.52 0 0 50002.48
6 32843.55 0 0 32843.55
7 36063.75 0 0 36063.75
8 35093.81 0 0 35093.81
9 10873.63 0 0 10873.63
And I want it to look like this:

1 35714.57
1 0
1 0
1 34365.98
1 0
1 35714.57
2 23874.54
2 0
2 23843.06
2 22860.84
2 0
2 23874.54

The existing data extend to 20 or more columns and there will be 9000 rows.


Sub ShowTwst()
Test_1 [a1:d4]
End Sub

Sub Test_1(rng As Excel.Range)
Dim v()
Dim res()
Dim R As Long, C As Long, L1 As Long, L2 As Long
Dim i As Long
Dim DestRng As Excel.Range

v = rng

R = UBound(v, 1)
C = UBound(v, 2)
ReDim res(1 To R * (C - 1), 1 To 2)

For L1 = 1 To R
For L2 = 2 To C
i = i + 1
res(i, 1) = v(L1, 1)
res(i, 2) = v(L1, L2)
Next L2
Next L1

Set DestRng = Nuovo_Range(ThisWorkbook)
DestRng.Resize(R * (C - 1), 2) = res


End Sub

Function Nuovo_Range( _
Wb As Excel.Workbook, _
Optional Nome_base As _
String = "Res") As Excel.Range

'restituisce la cella A1 di un nuovo foglio
'il nuovo foglio viene rinominato in base
'all'argomento Nome_base

Dim b As Long
Set Nuovo_Range = Wb.Worksheets.Add.Range("A1")

Application.ScreenUpdating = False
On Error Resume Next
Do
Err.Clear
b = b + 1
Nuovo_Range.Parent.Name = Nome_base & b
Loop While Err
Application.ScreenUpdating = True

End Function


regards
r

Il mio ultimo lavoro ...
http://excelvba.altervista.org/blog/...ternative.html

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a Grid (or range) of Data to a List a Excel Worksheet Functions 1 April 12th 07 10:14 PM
Converting Test Scores to somewhat of a Linear Transformation [email protected] Excel Worksheet Functions 6 February 11th 07 01:30 PM
Grid lines in Excel not showing.Have tools,options,view/grid cked bajlearning Excel Discussion (Misc queries) 6 January 28th 07 02:00 AM
data set for linear regression [email protected] Excel Programming 1 October 24th 06 06:56 PM
Converting grid data to side-by-side lists The Chad Excel Discussion (Misc queries) 6 July 27th 05 03:47 PM


All times are GMT +1. The time now is 07:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"