|
楼主 |
发表于 2016-8-29 10:01
|
显示全部楼层
本帖最后由 定敏 于 2016-8-29 10:04 编辑
老师您好,为了生成外来就读的学生名单,我试着套用您的代码,实现了大部分功能,可还有一些不该出现的内容也出现了(如一些空格,有的学校还把表头也复制了上来),您能帮我看看问题出现在哪里吗?谢谢
Sub test21()
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:l" & 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 10, 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) = Mid(xmarr, 6, 4)
brr(10, m) = arr(i, 12)
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
如图所示,中间有了些空格和不该有的表头。
|
|