Public d As Object
Private Sub cmd_exit_Click()
Unload UserForm1
End Sub
Private Sub cmd_ok_Click()
With Me
If .ComboBox1.ListIndex <> -1 And .ComboBox2.ListIndex <> -1 And .ComboBox3.ListIndex <> -1 And .ComboBox4.ListIndex <> -1 And .TextBox5.Text <> "" And .TextBox6.Text <> "" Then
nj = .ComboBox1.Text
bj = .ComboBox2.Text
xh = Val(.ComboBox4.Text)
If d.exists(nj) Then
If d(nj).exists(bj) Then
If d(nj)(bj).exists(xh) Then
brr = d(nj)(bj)(xh)
n = .ComboBox3.ListIndex + 4
m = brr(1) + 3
With Worksheets(nj)
.Cells(m, n) = Val(Me.TextBox6.Text)
End With
End If
End If
End If
End If
End With
End Sub
Private Sub ComboBox1_Change()
With Me
nj = .ComboBox1.Text
With .ComboBox2
.List = d(nj).keys
End With
End With
End Sub
Private Sub ComboBox2_Change()
With Me
nj = .ComboBox1.Text
bj = .ComboBox2.Text
With .ComboBox4
.List = d(nj)(bj).keys
End With
End With
End Sub
Private Sub ComboBox4_Change()
With Me
nj = .ComboBox1.Text
bj = .ComboBox2.Text
xh = Val(.ComboBox4.Text)
brr = d(nj)(bj)(xh)
.TextBox5.Value = brr(0)
End With
End Sub
Private Sub Label3_Click()
End Sub
Private Sub UserForm_Initialize()
Dim r%, i%
Dim arr, brr
Dim ws As Worksheet
Set d = CreateObject("scripting.dictionary")
For Each ws In Worksheets
If ws.Name Like "*年级" Then
Set d(ws.Name) = CreateObject("scripting.dictionary")
With ws
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a4:c" & r)
For i = 1 To UBound(arr)
If Not d(ws.Name).exists(arr(i, 2)) Then
Set d(ws.Name)(arr(i, 2)) = CreateObject("scripting.dictionary")
End If
d(ws.Name)(arr(i, 2))(arr(i, 1)) = Array(arr(i, 3), i)
Next
End With
End If
Next
With Me
With .ComboBox1
.List = d.keys
End With
With .ComboBox3
.List = Array("语文", "数学", "英语")
.ListIndex = 0
End With
End With
End Sub