|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 aman1516 于 2015-12-5 00:36 编辑
试试:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wb As Object, sh As Worksheet, arr, krr, i, j, k, m, n, c, t
Application.ScreenUpdating = False
On Error Resume Next
If Target.Count > 1 Then Exit Sub
If Target.Column <> 2 And Target.Row < 2 Then Exit Sub
If Dir(ThisWorkbook.Path & "\数据表.xls") = "" Then
MsgBox ThisWorkbook.Path & "\AAA.xls 文件不存在,请确认并重新导出"
Exit Sub
End If
Set wb = GetObject(ThisWorkbook.Path & "\数据表.xls")
1 ReDim arr(1 To 1000, 1 To 11)
shn = Array("表一", "表二", "表三")
For i = 0 To UBound(shn)
With wb.Sheets(shn(i))
r = .Range("C65536").End(xlUp).Row
krr = .Range("A2:K" & r)
For m = 1 To UBound(krr)
k = k + 1
For n = 1 To 11
arr(k, n) = krr(m, n)
Next
Next
End With
Next
For q = 1 To k
If arr(q, 3) = Target.Value Then
z = z + 1
If z = 1 Then
Target.Offset(0, 1) = arr(q, 4)
Target.Offset(0, 2) = arr(q, 10)
Target.Offset(0, 3) = arr(q, 11)
Else
Target.Offset(0, 1) = Target.Offset(0, 1) & "," & arr(q, 4)
Target.Offset(0, 2) = Target.Offset(0, 2) & "," & arr(q, 10)
Target.Offset(0, 3) = Target.Offset(0, 3) & "," & arr(q, 11)
End If
End If
Next
Set wb2 = Nothing
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|