當前位置:成語大全網 - 新華字典 - 求EXcel VBA字典解決3個工作表數據串聯匹配,得出查詢結果(如圖片描述),謝謝

求EXcel VBA字典解決3個工作表數據串聯匹配,得出查詢結果(如圖片描述),謝謝

直接編寫代碼可以解決!

Sub?ss()

Dim?MyRows1?As?Long

Dim?MyRows2?As?Long

Dim?MyRows3?As?Long

Dim?MyRows4?As?Long

Dim?Name1?As?String

Dim?Name2?As?String

Dim?Name3?As?String

Dim?MyData?As?Single

With?Excel.Application.ActiveWorkbook

MyRows4?=?1

MyRows3?=?3

Do?While?.Sheets("Sheet3").Cells(MyRows3,?1)?<>?""

Name1?=?.Sheets("Sheet3").Cells(MyRows3,?1)

Name2?=?.Sheets("Sheet3").Cells(MyRows3,?2)

MyRows2?=?3

Name3?=?""

Do?While?.Sheets("Sheet2").Cells(MyRows2,?1)?<>?""

If?.Sheets("Sheet2").Cells(MyRows2,?1)?=?Name1?And?.Sheets("Sheet2").Cells(MyRows2,?2)?=?Name2?Then

Name3?=?.Sheets("Sheet2").Cells(MyRows2,?3)

Exit?Do

End?If

MyRows2?=?MyRows2?+?1

Loop

If?Name3?<>?""?Then

MyData?=?-999.999

MyRows1?=?3

Do?While?.Sheets("Sheet1").Cells(MyRows1,?1)?<>?""

If?.Sheets("Sheet1").Cells(MyRows1,?1)?=?Name1?And?.Sheets("Sheet1").Cells(MyRows1,?2)?=?Name3?Then

MyData?=?.Sheets("Sheet1").Cells(MyRows2,?3)

Exit?Do

End?If

MyRows1?=?MyRows1?+?1

Loop

End?If

If?MyData?<>?-999.999?Then

MyRows4?=?MyRows4?+?1

.Sheets("Sheet4").Cells(MyRows4,?1)?=?Name1

.Sheets("Sheet4").Cells(MyRows4,?2)?=?Name2

.Sheets("Sheet4").Cells(MyRows4,?3)?=?Name3

.Sheets("Sheet4").Cells(MyRows4,?4)?=?MyData

End?If

MyRows3?=?MyRows3?+?1

Loop

End?With

End?Sub