在excel中能正确运行的vba代码,怎样改写成vb中的代码做成dll文件来调用?求高手帮忙改写一下! vba代码如下: Sub mc() Sheets(1).Unprotect Password:="123456" Sheets("xscj").Unprotect Password:="123456" cjzhs = Sheets(1).[a1].CurrentRegion.Rows.Count '成绩表的总行数 cjzls = Sheets(1).[a1].CurrentRegion.Columns.Count - 1 '成绩表的总列数 Sheets("xscj").Select Cells.ClearContents Sheets(1).Select Range(Cells(1, 1), Cells(cjzhs, cjzls)).Select Selection.Copy Sheets("xscj").Select Range("a1").Select Selection.PasteSpecial Paste:=xlPasteValues Application.CutCopyMode = False Worksheets("xscj").Range(Cells(2, 1), Cells(cjzhs, cjzls)).Sort Key1:=Worksheets("xscj").Range("a2"), Order1:=xlAscending, Key2:=Worksheets("xscj").Range("c2"), Order2:=xlAscending '以科类班级排序,使文科理科分开同一班的在一起 kml = 7 'InputBox("请输入第一个学科所在的列号(数值):") * 1 Cells(1, cjzls + 1) = "平均" Cells(1, cjzls + 2) = "总分" Cells(1, cjzls + 3) = "班名" Cells(1, cjzls + 4) = "年名" For i = 1 To cjzls - kml + 1 Cells(1, cjzls + 4 + i) = Left(Cells(1, kml + i - 1), 1) & "名" Next i wlkb = Cells(2, 1) krs = WorksheetFunction.CountIf(Range(Cells(2, 1), Cells(cjzhs, 1)), wlkb) '取该科号的人数 bjh = Cells(2, 3) kbh = 2 brs = WorksheetFunction.CountIf(Range(Cells(2, 3), Cells(kbh + krs - 1, 3)), bjh) '取该班号的人数 bjhh = 2 For i = 2 To cjzhs If WorksheetFunction.Sum(Range(Cells(i, kml), Cells(i, cjzls))) Then Cells(i, cjzls + 2) = WorksheetFunction.Sum(Range(Cells(i, kml), Cells(i, cjzls))) If Cells(i, cjzls + 2) > 0 Then Cells(i, cjzls + 1) = Round(WorksheetFunction.Average(Range(Cells(i, kml), Cells(i, cjzls))), 2) Next i For i = 2 To cjzhs If wlkb = Cells(i, 1) Then If bjh <> Cells(i, 3) Then bjhh = i bjh = Cells(i, 3) brs = WorksheetFunction.CountIf(Range(Cells(i, 3), Cells(kbh + krs - 1, 3)), bjh) '取该班号的人数 End If Else kbh = i wlkb = Cells(i, 1) krs = WorksheetFunction.CountIf(Range(Cells(i, 1), Cells(cjzhs, 1)), wlkb) '取该科号的人数 bjhh = i bjh = Cells(i, 3) brs = WorksheetFunction.CountIf(Range(Cells(i, 3), Cells(kbh + krs - 1, 3)), bjh) '取该班号的人数 End If If Cells(i, cjzls + 2) > 0 Then Cells(i, cjzls + 3) = WorksheetFunction.Rank(Cells(i, cjzls + 2), Range(Cells(bjhh, cjzls + 2), Cells(bjhh + brs - 1, cjzls + 2))) Cells(i, cjzls + 4) = WorksheetFunction.Rank(Cells(i, cjzls + 2), Range(Cells(kbh, cjzls + 2), Cells(kbh + krs - 1, cjzls + 2))) End If For j = 1 To cjzls - kml + 1 If WorksheetFunction.IsNumber(Cells(i, kml + j - 1)) Then Cells(i, cjzls + 4 + j) = WorksheetFunction.Rank(Cells(i, kml + j - 1), Range(Cells(kbh, kml + j - 1), Cells(kbh + krs - 1, kml + j - 1))) Next j Next i Sheets("xscj").Protect Password:="123456", AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowSorting:=True, UserInterfaceOnly:=True Sheets(1).Protect Password:="123456", AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, UserInterfaceOnly:=True End Sub 先谢谢各位高手来帮我一下。
|