Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / September 2005

Tip: Looking for answers? Try searching our database.

help converting table structure

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Barnett - 27 Sep 2005 21:57 GMT
hi - i'm a teacher and am after some help changing the structure of a large
table.

i am given every few weeks an excel table with the structure

Columns:  Admin    RedMon    RedTue    RedWed    RedThu    RedFri    BluMon
BluTue    BluWed    BluThu    BluFri

The Admin is a number assigned to each pupil in the school (1400 on role)
In the RedMon, RedTue etc columns is a room number.

I could do with the structure of the table being changed to the following

Admin        Cycle (Red/Blue)    Day    Room

So that each pupil will now have 10 entries (one for each day of the 2 week
cycle)

i hope that this is easy to understand.

This is actually then to be imported into Access for use as part of a
database.

I would be grateful for any help anyone could give me with this.

thanks
Chris Barnett
chrisbarnettspamoff@tiscali.co.uk
Dave Peterson - 28 Sep 2005 03:06 GMT
I think that this works...

Option Explicit
Sub testme01()

   Dim curWks As Worksheet
   Dim newWks As Worksheet
   Dim iRow As Long
   Dim iCol As Long
   Dim FirstRow As Long
   Dim LastRow As Long
   Dim oRow As Long
   
   Set curWks = Worksheets("sheet1")
   Set newWks = Worksheets.Add
   
   newWks.Range("A1").Resize(1, 4).Value _
       = Array("Admin", "Cycle (Red/Blue)", "Day", "Room")
   oRow = 1
   
   With curWks
       FirstRow = 2
       LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
       
       For iRow = FirstRow To LastRow
           For iCol = 2 To 11
               If IsEmpty(.Cells(iRow, iCol)) Then
                   'do nothing
               Else
                   oRow = oRow + 1
                   newWks.Cells(oRow, "A").Value = .Cells(iRow, "A").Value
                   newWks.Cells(oRow, "B").Value _
                                         = Left(.Cells(1, iCol).Value, 3)
                   newWks.Cells(oRow, "C").Value = Mid(.Cells(1, iCol), 4)
                   newWks.Cells(oRow, "D").Value = .Cells(iRow, iCol).Value
               End If
           Next iCol
       Next iRow
   End With
   
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

> hi - i'm a teacher and am after some help changing the structure of a large
> table.
[quoted text clipped - 24 lines]
> Chris Barnett
> chrisbarnettspamoff@tiscali.co.uk

Signature

Dave Peterson

Chris Barnett - 29 Sep 2005 20:56 GMT
just thought i'd let you know that i've used your code and after a minor
tweak and me getting my head round using macros it works a treat.

so thanks very much for you help.

cheers
Chris

>I think that this works...
>
[quoted text clipped - 73 lines]
>> Chris Barnett
>> chrisbarnettspamoff@tiscali.co.uk
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.