PC Review


Reply
Thread Tools Rate Thread

Arrange Data Matrix into List for Access

 
 
ra
Guest
Posts: n/a
 
      31st Oct 2008
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.

 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      31st Oct 2008
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.
>
>

 
Reply With Quote
 
ra
Guest
Posts: n/a
 
      31st Oct 2008
On Oct 31, 10:58*am, Joel <J...@discussions.microsoft.com> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to arrange list by first or last name Andy Microsoft Excel Misc 1 27th May 2010 11:02 PM
Multiple Matrix calculations from data list =?Utf-8?B?R2FyeSBC?= Microsoft Excel Misc 11 23rd Oct 2006 06:43 PM
how can I arrange a list by a date? =?Utf-8?B?bGxhdm8=?= Microsoft Word Document Management 2 10th Apr 2006 05:24 AM
Arrange a list in ComboBox Syed Haider Ali Microsoft Excel Programming 1 12th Aug 2005 11:27 PM
Display data list in Matrix =?Utf-8?B?QW5keQ==?= Microsoft Excel Worksheet Functions 2 20th Nov 2003 01:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:27 PM.