antinora
Board Regular
- Joined
- Dec 4, 2013
- Messages
- 87
- Office Version
- 365
- 2016
- Platform
- Windows
Greetings: Here is a table of teacher data. In each cell is course code, course name, pass percentage, & department all in a single string. I plan on using Text-to-Column after I run the VBA below. The VBA (which I've used in the past) sets up a array of tabs, one for each department. The code then scans each line & populates each tab with cells containing the same department name using Case commands.
I've used this code for student class data & it has worked out to 9 columns.
When I run it with data below (in reality we have 168 teacher meaning 169 rows) the code only populates columns C & E for each tab. Also, it doesn't scan all rows.
I am unsure if my LBound to UBound is in error. Being a VBA novice I am unsure which command tells the VBA to scan each line.
Any help is appreciated by both me & my students. Thanks
John A.
Excel 2010
<tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: center"]5[/TD]
</tbody>
I've used this code for student class data & it has worked out to 9 columns.
When I run it with data below (in reality we have 168 teacher meaning 169 rows) the code only populates columns C & E for each tab. Also, it doesn't scan all rows.
I am unsure if my LBound to UBound is in error. Being a VBA novice I am unsure which command tells the VBA to scan each line.
Any help is appreciated by both me & my students. Thanks
John A.
Excel 2010
A | B | C | D | E | F | G | H | I | |
---|---|---|---|---|---|---|---|---|---|
TEACHER | CLASS1 | CLASS2 | CLASS3 | CLASS4 | CLASS5 | CLASS6 | CLASS7 | CLASS8 | |
ABBRUSCATO | MES33QQT/1-Common Core Algebra 3 Term 3 of 3-0.5454545455-Mathematics | MES41Q9C/1-Common Core Algebra 1 Term 1 of 4-0.7894736842-Mathematics | MES41QEL/1-Common Core Algebra 1 Term 1 of 4-0.4444444444-Mathematics | MES42Q9C/1-Common Core Algebra 1 Term 2 of 4-0.7894736842-Mathematics | MES42QEL/1-Common Core Algebra 1 Term 1 of 4-0.4444444444-Mathematics | ||||
AMALFITANO | PFS11/1-Fitness For Life-0.5957446809-Phys Ed | PFS11/2-Fitness For Life-0.5777777778-Phys Ed | PFS11/3-Fitness For Life-0.6744186047-Phys Ed | PGS11/4-Strength Training-0.72-Phys Ed | PGS11/6-Strength Training-0.6222222222-Phys Ed | ||||
ANDRE | EAS11QWR/1-Wilson Reading-0.6-ELA | EAS11QWR/2-Wilson Reading-0.8333333333-ELA | EAS11QWR/3-Wilson Reading-1-ELA | EES85QQM/1-English 5-0.7333333333-ELA | SLS21Q9S/13-Living Environment 1-1-Science | SLS21QLS/30-Living Environment 1 LAB-1-Science | ZY/2-Regents Skills-0.6-OSPAA | ||
ANTHONY | SES21QLR/19-Earth Science 1 LAB-0.8095238095-Science | SES21QLR/9-Earth Science 1 LAB-0.5833333333-Science | SES21QLX/14-Earth Science 1 LAB-0.6818181818-Science | SES21QLX/3-Earth Science 1 LAB-0.8620689655-Science | SES21QQR/8-Earth Science 1-0.8571428571-Science | SES21QQR/9-Earth Science 1-0.8333333333-Science | SES21QQX/14-Earth Science 1-0.7727272727-Science | SES21QQX/3-Earth Science 1-0.8518518519-Science |
<tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: center"]5[/TD]
</tbody>
Sheet1
VBA:
Code:
Sub breakOut()Dim sh As Worksheet, c As Range, fn As Range, sAry As Variant
Set sh = Sheets("sheet1")
sAry = Array("ELA", "Mathematics", "Science", "Social Studies", "OSPAA", "Art", " Foreign Language", "Phys Ed")
For i = LBound(sAry) To UBound(sAry)
Sheets.Add After:=sh
ActiveSheet.Name = sAry(i)
sh.Range("A1:B1").Copy ActiveSheet.Range("A1")
'ActiveSheet.Range("C1") = "Subj/Tchr"
ActiveSheet.Columns("A:C").AutoFit
For Each c In sh.Range("A2", sh.Cells(Rows.Count, 1).End(xlUp))
Select Case sAry(i)
Case "ELA"
ltr = "ELA"
Case "Mathematics"
ltr = "Mathematics"
Case "Science"
ltr = "Science"
Case "Social Studies"
ltr = "Social Studies"
Case "OSPAA"
ltr = "OSPAA"
Case "Art"
ltr = "Art"
Case "Foreign Language"
ltr = "Foreign Language"
Case "Phys Ed"
ltr = "Phys Ed"
End Select
Set fn = c.Offset(, 3).Resize(1, 9).Find(ltr, , xlValues)
If Not fn Is Nothing Then
Sheets(sAry(i)).Cells(Rows.Count, 1).End(xlUp)(2) = c.Value
Sheets(sAry(i)).Cells(Rows.Count, 1).End(xlUp).Offset(, 1) = c.Offset(, 1).Value
Sheets(sAry(i)).Cells(Rows.Count, 1).End(xlUp).Offset(, 2) = fn.Value
End If
Next
Next
End Sub