EXCLE(vba)说明——方便自己回顾

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim d, wb As Workbook, ar

Set d = CreateObject("Scripting.Dictionary")

Set wb = GetObject(ThisWorkbook.Path & "\Book1.xlsx")

Application.ScreenUpdating = False

ar = wb.Sheets(1).Range("A1").CurrentRegion

wb.Close 0

For i = 2 To UBound(ar)

d(ar(i, 1)) = Array(ar(i, 2), ar(i, 3))

Next

For i = 2 To [b65536].End(3).Row

Cells(i, 3).Resize(1, 2) = d(Cells(i, 2).Value)

Next

Application.ScreenUpdating = True

End Sub

输入单元格触发

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub


d(ar(i, 1)) = Array(ar(i, 2), ar(i, 3))

EXCLE(vba)说明——方便自己回顾_第1张图片

d(ar(i, 1)) = Array(ar(i, 2), ar(i, 3))   → d(ar(i, 1)) = Array(ar(i, 2), ar(i, 2)

EXCLE(vba)说明——方便自己回顾_第2张图片

d(ar(i, 1)) = Array(ar(i, 2), ar(i, 3))  → d(ar(i, 1)) = Array(ar(i,1), ar(i, 3))

EXCLE(vba)说明——方便自己回顾_第3张图片

Cells(i, 3).Resize(1, 2) = d(Cells(i, 2).Value) → Cells(i, 3).Resize(1, 2) = d(Cells(i, 1).Value)

EXCLE(vba)说明——方便自己回顾_第4张图片

Cells(i, 3).Resize(1, 2) = d(Cells(i,2).Value) → Cells(i, 3).Resize(1, 3) = d(Cells(i,2).Value)

EXCLE(vba)说明——方便自己回顾_第5张图片

Cells(i, 3).Resize(1, 2) = d(Cells(i, 2).Value) → Cells(i, 3).Resize(2, 2) = d(Cells(i, 2).Value)

EXCLE(vba)说明——方便自己回顾_第6张图片

Cells(i, 3).Resize(1, 2) = d(Cells(i, 2).Value) → Cells(i, 4).Resize(1, 2) = d(Cells(i, 2).Value)

EXCLE(vba)说明——方便自己回顾_第7张图片

你可能感兴趣的:(EXCLE(vba)说明——方便自己回顾)