ความคิดเห็นที่ 25
15.11 น. ตอนนี้ได้โค้ดสำหรับสร้างตารางแบบสมบูรณ์ ออกมาแล้วครับ ผลการตรวจสอบกับโปรแกรมอีกอัน หนึ่งที่ออกแบบเมื่อปีที่แล้ว ก็ได้ผลตรงกัน
Sub ProcessQEAAAInfo() Dim YearCond(1 To 100) As Integer Dim DeptCount(1 To 100) As Integer Dim MethodCount(1 To 100) As Integer Dim DeptName(1 To 100, 1 To 10) As String Dim MethodName(1 To 100, 1 To 10) As String Dim SumRow(1 To 100, 1 To 10) As Integer Dim SumCol(1 To 100, 1 To 10) As Integer Dim CountIndivDeptMeth(1 To 100, 1 To 10, 1 To 10) As Long N = ActiveWorkbook.Sheets.Count ii = 0 For i = 1 To N If IsNumeric(Sheets(i).Name) = True Then ii = ii + 1 Sheets(i).Select YearCond(ii) = CInt(Sheets(i).Name) + 2500 k = 0 DeptCount(ii) = 0 Do k = k + 1 If k = 1 Then DeptName(ii, k) = Cells(k + 5, 6) DeptCount(ii) = DeptCount(ii) + 1 Else Temp = Cells(k + 5, 6) Repetition = False For j = 1 To DeptCount(ii) If Temp = DeptName(ii, j) Then Repetition = True End If Next j If Repetition = False Then DeptCount(ii) = DeptCount(ii) + 1 DeptName(ii, DeptCount(ii)) = Cells(k + 5, 6) End If End If Loop Until Cells(k + 6, 2) = "" k = 0 MethodCount(ii) = 0 Do k = k + 1 Temp = Trim(Cells(k + 5, 7)) If Temp = "" Then If IsNumeric(Cells(k + 5, 9)) = False Then Temp = "No Info (absentee)" Else Temp = "No Info (incomplete data)" End If End If Repetition = False For j = 1 To MethodCount(ii) If Temp = MethodName(ii, j) Then Repetition = True End If Next j If Repetition = False Then MethodCount(ii) = MethodCount(ii) + 1 MethodName(ii, MethodCount(ii)) = Temp End If Loop Until Cells(k + 6, 2) = "" End If YearCount = ii Next i For i = 1 To YearCount Sheets(CStr(YearCond(i) - 2500)).Select h = 0 'MsgBox DeptCount(i) & " " & MethodCount(i) Do h = h + 1 Temp1 = Cells(h + 5, 6) Temp2 = Cells(h + 5, 7) If Temp2 = "" Then If IsNumeric(Cells(h + 5, 9)) = False Then Temp2 = "No Info (absentee)" Else Temp2 = "No Info (incomplete data)" End If End If For k = 1 To DeptCount(i) For j = 1 To MethodCount(i) 'MsgBox Temp1 & " " & DeptName(i, k) & Chr(13) & Temp2 & " " & MethodName(i, j) If Temp1 = DeptName(i, k) And Temp2 = MethodName(i, j) Then CountIndivDeptMeth(i, k, j) = CountIndivDeptMeth(i, k, j) + 1 GoTo 1: End If Next j Next k 1: Loop Until Cells(h + 5, 2) = "" 'If i = 1 Then Stop Next i 'Test_YearCond & DeptName Sheets("Summary2").Select Cells.Clear CountLine = 0 For i = 1 To ii Cells(i + CountLine, 4) = "Total" Cells(i + CountLine + 1, 1) = "Year" Cells(i + CountLine + 1, 2) = YearCond(i) For j = 1 To DeptCount(i) Cells(i + CountLine, 4 + j) = DeptName(i, j) Next j For j = 1 To MethodCount(i) Cells(i + CountLine + j, 3) = MethodName(i, j) Next j CheckSum1 = 0 For k = 1 To DeptCount(i) For l = 1 To MethodCount(i) Cells(i + CountLine + l, 4 + k) = CountIndivDeptMeth(i, k, l) SumCol(i, k) = SumCol(i, k) + CountIndivDeptMeth(i, k, l) Next l Cells(i + CountLine + 1 + MethodCount(i), 4 + k) = SumCol(i, k) CheckSum1 = CheckSum1 + SumCol(i, k) Next k CheckSum2 = 0 For k = 1 To MethodCount(i) For l = 1 To DeptCount(i) SumRow(i, k) = SumRow(i, k) + CountIndivDeptMeth(i, l, k) Next l Cells(i + CountLine + k, 4) = SumRow(i, k) CheckSum2 = CheckSum2 + SumRow(i, k) Next k Cells(i + CountLine + 1 + MethodCount(i), 3) = "Overall" If CheckSum1 = CheckSum2 Then Cells(i + CountLine + 1 + MethodCount(i), 4) = CheckSum1 Range(Cells(i + CountLine, 4), Cells(i + CountLine + 1 + MethodCount(i), 4)).Font.ColorIndex = 5 Range(Cells(i + CountLine, 4), Cells(i + CountLine + 1 + MethodCount(i), 4)).Font.Bold = True Range(Cells(i + CountLine + 1 + MethodCount(i), 1), Cells(i + CountLine + 1 + MethodCount(i), 4 + DeptCount(i))).Font.ColorIndex = 3 Range(Cells(i + CountLine + 1 + MethodCount(i), 1), Cells(i + CountLine + 1 + MethodCount(i), 4 + DeptCount(i))).Font.Bold = True Cells(i + CountLine + 1 + MethodCount(i), 4).Font.ColorIndex = 13 Cells(i + CountLine + 1 + MethodCount(i), 4).Font.Bold = True Cells(i + CountLine + 1 + MethodCount(i), 4).Font.Underline = xlUnderlineStyleSingle CountLine = CountLine + MethodCount(i) + 3 Next i Cells.Columns.AutoFit End Sub
จากคุณ :
Practical x 2
- [
วันจักรี 15:20:19
]
|
|
|