Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ra ra is offline
external usenet poster
 
Posts: 27
Default Arrange Data Matrix into List for Access

Hello,

Using Access for a number of calculation and have a lot of source data
in this format:

Name OCT NOV DEC
A 0 1 1
B 1 0.5 0
C 1 0 0
D 1 1 1


That I need to rearrange into this format:

A OCT 0
B OCT 1
C OCT 1
D OCT 1
A NOV 1
B NOV 0.5
C NOV 0
D NOV 1
A DEC 1
B DEC 0
C DEC 0
D DEC 1


I have some simple code for set ranges but ideally want to be able to
run one macro for differening number rows and columns.
Any help appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Arrange Data Matrix into List for Access

Try this code. It is generic. you should be able to modify as needed.


Sub main()
Dim Table As Range
Dim DestinationLoc As Range

With Sheets("Sheet1")
Set StartCell = .Range("A1")
LastCol = StartCell.End(xlToRight).Column
LastRow = StartCell.End(xlDown).Row
Set Table = .Range(StartCell, .Cells(LastRow, LastCol))
End With
Set DestinationLoc = Sheets("Sheet2").Range("A1")
Call MakeRows(Table, DestinationLoc)

End Sub
Sub MakeRows(Target As Range, Destination As Range)

NumCols = Target.Columns.Count
NumRows = Target.Rows.Count
NewRowOffset = 0
'Skip header row
For RowOffset = 2 To NumRows
'skip header column
For ColOffset = 2 To NumCols
Destination.Offset(NewRowOffset, 0) = Target(RowOffset, 1).Value
Destination.Offset(NewRowOffset, 1) = Target(1, ColOffset).Value
Destination.Offset(NewRowOffset, 2) = Target(RowOffset, ColOffset)
NewRowOffset = NewRowOffset + 1
Next ColOffset
Next RowOffset
End Sub


"ra" wrote:

Hello,

Using Access for a number of calculation and have a lot of source data
in this format:

Name OCT NOV DEC
A 0 1 1
B 1 0.5 0
C 1 0 0
D 1 1 1


That I need to rearrange into this format:

A OCT 0
B OCT 1
C OCT 1
D OCT 1
A NOV 1
B NOV 0.5
C NOV 0
D NOV 1
A DEC 1
B DEC 0
C DEC 0
D DEC 1


I have some simple code for set ranges but ideally want to be able to
run one macro for differening number rows and columns.
Any help appreciated.


  #3   Report Post  
Posted to microsoft.public.excel.programming
ra ra is offline
external usenet poster
 
Posts: 27
Default Arrange Data Matrix into List for Access

On Oct 31, 10:58*am, Joel wrote:
Try this code. *It is generic. *you should be able to modify as needed.

Sub main()
Dim Table As Range
Dim DestinationLoc As Range

With Sheets("Sheet1")
* *Set StartCell = .Range("A1")
* *LastCol = StartCell.End(xlToRight).Column
* *LastRow = StartCell.End(xlDown).Row
* *Set Table = .Range(StartCell, .Cells(LastRow, LastCol))
End With
Set DestinationLoc = Sheets("Sheet2").Range("A1")
Call MakeRows(Table, DestinationLoc)

End Sub
Sub MakeRows(Target As Range, Destination As Range)

NumCols = Target.Columns.Count
NumRows = Target.Rows.Count
NewRowOffset = 0
'Skip header row
For RowOffset = 2 To NumRows
* *'skip header column
* *For ColOffset = 2 To NumCols
* * * Destination.Offset(NewRowOffset, 0) = Target(RowOffset, 1).Value
* * * Destination.Offset(NewRowOffset, 1) = Target(1, ColOffset).Value
* * * Destination.Offset(NewRowOffset, 2) = Target(RowOffset, ColOffset)
* * * NewRowOffset = NewRowOffset + 1
* *Next ColOffset
Next RowOffset
End Sub



"ra" wrote:
Hello,


Using Access for a number of calculation and have a lot of source data
in this format:


Name * * * OCT * * NOV * * DEC
A *0 * * * 1 * * * 1
B *1 * * * 0.5 * * 0
C *1 * * * 0 * * * 0
D *1 * * * 1 * * * 1


That I need to rearrange into this format:


A *OCT * * 0
B *OCT * * 1
C *OCT * * 1
D *OCT * * 1
A *NOV * * 1
B *NOV * * 0.5
C *NOV * * 0
D *NOV * * 1
A *DEC * * 1
B *DEC * * 0
C *DEC * * 0
D *DEC * * 1


I have some simple code for set ranges but ideally want to be able to
run one macro for differening number rows and columns.
Any help appreciated.- Hide quoted text -


- Show quoted text -


Excellent, very clever thanks
Reply
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
how to arrange list by first or last name Andy Excel Discussion (Misc queries) 1 May 27th 10 11:02 PM
how do i arrange list of names alphabetically in excel? ganna pritesh New Users to Excel 2 March 18th 09 03:42 PM
Populate ComboBox list with Access data IT_roofer Excel Programming 10 April 11th 07 11:31 PM
Multiple Matrix calculations from data list Gary B Excel Discussion (Misc queries) 11 October 23rd 06 06:43 PM
Arrange a list in ComboBox Syed Haider Ali[_9_] Excel Programming 1 August 12th 05 11:27 PM


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

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

About Us

"It's about Microsoft Excel"