|
楼主 |
发表于 2023-8-11 17:01
|
显示全部楼层
老师:麻烦看看我根据需要修改的代码哪里有问题?谢谢
Sub test()
'On Error Resume Next
Dim r%, i%
Dim arr, brr
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Worksheets("考场信息")
.AutoFilterMode = False
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a3:n" & r)
End With
For i = 1 To UBound(arr)
If Not d.exists(arr(i, 7)) Then
Set d(arr(i, 7)) = CreateObject("scripting.dictionary")
End If
d(arr(i, 7))(i) = Empty
Next
For Each aa In d.keys
With Worksheets(aa) '运行时这里提示下标越界
ReDim brr(1 To d(aa).Count, 1 To 8)
m = 0
For Each bb In d(aa).keys
m = m + 1
'brr(m, 1) = arr(bb, 1) '序号
brr(m, 2) = arr(bb, 4) '学籍号
brr(m, 3) = arr(bb, 6) '身份证号
brr(m, 4) = arr(bb, 8) '班级
brr(m, 5) = arr(bb, 2) '姓名
brr(m, 6) = arr(bb, 5) '考号
brr(m, 7) = arr(bb, 11) '考场
brr(m, 8) = arr(bb, 13) '考场号-----新增加一列关键字
Next
.UsedRange.Offset(3, 0).Resize(UBound(brr), 8).ClearContents '只清除1-8列数据?
.Range("a:b,e:e").NumberFormatLocal = "@"
.Range("a4").Resize(UBound(brr), UBound(brr, 2)) = brr
With .UsedRange
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End With
Next
End Sub |
|