|
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
wj = ListBox1.List(i, 0)
Exit For
End If
Next i
lj = ThisWorkbook.Path & "\"
f = Dir(lj & "数据源.xlsx")
If f = "" Then MsgBox "找不到数据源文件!": Exit Sub
Set wb = Workbooks.Open(lj & f, 0)
ar = wb.Worksheets(1).[a1].CurrentRegion
wb.Close False
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
d(ar(i, 1)) = i
End If
Next i
Set wb = Nothing
Windows(wj).Activate
br = ActiveWorkbook.Worksheets(1).[a1].CurrentRegion
For i = 2 To UBound(br)
If br(i, 1) <> "" Then
xh = d(br(i, 1))
If xh <> "" Then
br(i, 2) = ar(xh, 2)
End If
End If
Next i
ActiveWorkbook.Worksheets(1).[a1].CurrentRegion = br
End Sub
Private Sub UserForm_Initialize()
Dim wb As Workbook
Dim br()
ReDim br(1 To 3, 1 To 1)
For Each wb In Workbooks
If wb.Name <> ThisWorkbook.Name And InStr(wb.Name, "数据源") = 0 Then
n = n + 1
br(n, 1) = wb.Name
End If
Next wb
If n = "" Then MsgBox "请先打开结果文件!": Exit Sub
ListBox1.List = br
End Sub
|
评分
-
1
查看全部评分
-
|