|
楼主 |
发表于 2016-8-25 14:03
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 定敏 于 2016-8-25 14:22 编辑
我试着套用chxw68 老师的代码想用来完成8楼的功能,可不知为什么总是不能出现我要的结果,这是哪里有问题了:
Sub test1()
Dim r%, i%, m%
Dim arr, brr()
Dim mypath$, myname$
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
mypath = ThisWorkbook.Path
myname = Dir(mypath & "\*.xls")
Do While myname <> ""
If myname <> ThisWorkbook.Name Then
Set wb = GetObject(mypath & "\" & myname)
With wb
With .Worksheets("在校生名册")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a8:p" & r)
xmarr = .Range("a4")
For i = 1 To UBound(arr)
If Mid(arr(i, 10), 7, 2) <> Left(Right(xmarr, 4), 2) Then
m = m + 1
ReDim Preserve brr(1 To 12, 1 To m)
brr(1, m) = m
brr(2, m) = arr(i, 4)
brr(3, m) = arr(i, 5)
brr(4, m) = arr(i, 6)
brr(5, m) = arr(i, 7)
brr(6, m) = arr(i, 8)
brr(7, m) = arr(i, 9)
brr(8, m) = arr(i, 10)
brr(9, m) = arr(i, 11)
brr(10, m) = Mid(xmarr, 6, 4)
End If
Next
End With
.Close
End With
End If
myname = Dir()
Loop
With Worksheets("外来就读学生名册")
.UsedRange.Offset(4, 0).Clear
.Range("a5").Resize(UBound(brr, 2), UBound(brr)) = Application.Transpose(brr)
r = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("a4:g" & r).Borders.LineStyle = xlContinuous
End With
End Sub
|
|