C
chrisbarnett.werneth
hi
i'm a teacher and have created a reporting database. for my database
to work i have an reports table that looks like this that has the
following fields.
Admin No : unique pupil number
Subject : subject studied
Set : class name that pupil is in for that subject
Attain : attainment grade
Classwork : letter grade
Homework : letter grade
Behaviour : letter grade
However i get the information from an internet database which i can
export data from in the form of an excel file.
The excel table is however in the following format: (reading as columns
across)
Admin No
Subject 1 Set
Subject 1 Attain
Subject 1 Class
Subject 1 Home
Subject 1 Beh
Subject 2 Set
Subject 2 Attain
Subject 2 Class
etc approx 34 subjects
So i created the following routine in Excel to convert the data to fit
my Access table.
Sub Convert_Assessment_Datatable()
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
Dim subjectname As String
Dim lastcol As Long
Set curWks = ActiveSheet
Set newWks = Worksheets.Add
newWks.Range("A1").Resize(1, 7).Value = Array("Admin", "Subject",
"Set", "Attain", "Class", "Hwk", "Beh")
oRow = 2
newWks.Range("A2").Resize(1, 4).Value = Array(1000, "delete",
"this", "row")
oRow = 3
With curWks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
For iRow = FirstRow To LastRow
For iCol = 6 To lastcol Step 5
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 + 1).Value, Len(.Cells(1, iCol + 1).Value) - 10)
newWks.Cells(oRow, "C").Value = .Cells(iRow,
iCol).Value
newWks.Cells(oRow, "D").Value = .Cells(iRow, iCol +
1).Value
newWks.Cells(oRow, "E").Value = .Cells(iRow, iCol +
2).Value
newWks.Cells(oRow, "F").Value = .Cells(iRow, iCol +
3).Value
newWks.Cells(oRow, "G").Value = .Cells(iRow, iCol +
4).Value
End If
Next iCol
Next iRow
End With
End Sub
What i'd really like to do (i need to let other users work this
database without my help) is set it up so that i can import the
original Excel table into Access and then run the convert routine as a
macro so that the table conversion is done all within the Access
database.
I hope this makes sense and thanks for any help that you can give
thanks
Chris Barnett
i'm a teacher and have created a reporting database. for my database
to work i have an reports table that looks like this that has the
following fields.
Admin No : unique pupil number
Subject : subject studied
Set : class name that pupil is in for that subject
Attain : attainment grade
Classwork : letter grade
Homework : letter grade
Behaviour : letter grade
However i get the information from an internet database which i can
export data from in the form of an excel file.
The excel table is however in the following format: (reading as columns
across)
Admin No
Subject 1 Set
Subject 1 Attain
Subject 1 Class
Subject 1 Home
Subject 1 Beh
Subject 2 Set
Subject 2 Attain
Subject 2 Class
etc approx 34 subjects
So i created the following routine in Excel to convert the data to fit
my Access table.
Sub Convert_Assessment_Datatable()
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
Dim subjectname As String
Dim lastcol As Long
Set curWks = ActiveSheet
Set newWks = Worksheets.Add
newWks.Range("A1").Resize(1, 7).Value = Array("Admin", "Subject",
"Set", "Attain", "Class", "Hwk", "Beh")
oRow = 2
newWks.Range("A2").Resize(1, 4).Value = Array(1000, "delete",
"this", "row")
oRow = 3
With curWks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
For iRow = FirstRow To LastRow
For iCol = 6 To lastcol Step 5
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 + 1).Value, Len(.Cells(1, iCol + 1).Value) - 10)
newWks.Cells(oRow, "C").Value = .Cells(iRow,
iCol).Value
newWks.Cells(oRow, "D").Value = .Cells(iRow, iCol +
1).Value
newWks.Cells(oRow, "E").Value = .Cells(iRow, iCol +
2).Value
newWks.Cells(oRow, "F").Value = .Cells(iRow, iCol +
3).Value
newWks.Cells(oRow, "G").Value = .Cells(iRow, iCol +
4).Value
End If
Next iCol
Next iRow
End With
End Sub
What i'd really like to do (i need to let other users work this
database without my help) is set it up so that i can import the
original Excel table into Access and then run the convert routine as a
macro so that the table conversion is done all within the Access
database.
I hope this makes sense and thanks for any help that you can give
thanks
Chris Barnett