最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

VBA——字典對象的常規(guī)用法和嵌套用法示例

2023-08-15 21:27 作者:ch_j  | 我要投稿

Rem 本視頻完整代碼

'方法一

Sub 字典匹配數(shù)據(jù)()

??Dim arr

??Dim i As Long

??Dim dict As Object

??Dim key As String

???

??arr = Sheets("長攤索引表").UsedRange.Value

??Set dict = CreateObject("Scripting.Dictionary")

???

??For i = LBound(arr, 1) + 1 To UBound(arr, 1)

????key = CStr(arr(i, 1))

?????

????If Not dict.Exists(key) Then

??????dict(key) = arr(i, 3)

????Else

??????dict(key) = dict(key) & "_" & arr(i, 3)

????End If

??Next i

???

??Dim brr

??Dim j As Long

??Dim key1

??Dim 新行 As Long

???

??brr = Sheets("輔材表").UsedRange.Value

??新行 = 2

??For j = LBound(brr, 1) + 1 To UBound(brr, 1)

????key1 = CStr(brr(j, 1))

?????

????If dict.Exists(key1) Then

??????If InStr(dict(key1), brr(j, 3)) > 0 Then

????????'數(shù)據(jù)滿足條件,需要存到【長攤表】中

????????With Sheets("長攤表")

??????????.Cells(新行, 1).Value = "'" & brr(j, 1)

??????????.Cells(新行, 2).Value = "'" & brr(j, 2)

??????????.Cells(新行, 3).Value = "'" & brr(j, 3)

????????End With

?????????

????????新行 = 新行 + 1

??????End If

????End If

??Next j

End Sub


'方法二

Sub 字典匹配數(shù)據(jù)_匹配3列_拼接key()

??Dim arr

??Dim i As Long

??Dim dict As Object

??Dim key As String

???

??arr = Sheets("長攤索引表").UsedRange.Value

??Set dict = CreateObject("Scripting.Dictionary")

???

??For i = LBound(arr, 1) + 1 To UBound(arr, 1)

????key = CStr(arr(i, 1)) & "_" & CStr(arr(i, 2)) & "_" & CStr(arr(i, 3))

?????

????If Not dict.Exists(key) Then

??????dict(key) = True

????End If

??Next i

???

??Dim brr

??Dim j As Long

??Dim key1

??Dim 新行 As Long

???

??brr = Sheets("輔材表").UsedRange.Value

??新行 = 2

??Sheets("長攤表").UsedRange.Rows.Delete

??For j = LBound(brr, 1) + 1 To UBound(brr, 1)

????key1 = CStr(brr(j, 1)) & "_" & CStr(brr(j, 2)) & "_" & CStr(brr(j, 3))

?????

????If dict.Exists(key1) Then

??????'數(shù)據(jù)滿足條件,需要存到【長攤表】中

??????With Sheets("長攤表")

????????.Cells(新行, 1).Value = "'" & brr(j, 1)

????????.Cells(新行, 2).Value = "'" & brr(j, 2)

????????.Cells(新行, 3).Value = "'" & brr(j, 3)

??????End With

???????

??????新行 = 新行 + 1

????End If

??Next j

End Sub


'方法三

Sub 字典匹配數(shù)據(jù)_字典嵌套()

??Dim arr

??Dim i As Long

??Dim dict As Object

??Dim dict1 As Object

??Dim key As String

??Dim key1 As String

???

??arr = Sheets("長攤索引表").UsedRange.Value

??Set dict = CreateObject("Scripting.Dictionary")

???

??For i = LBound(arr, 1) + 1 To UBound(arr, 1)

????key = CStr(arr(i, 1))

?????

????If Not dict.Exists(key) Then

??????Set dict(key) = CreateObject("Scripting.Dictionary")

????End If

?????

????'Set dict1 = dict(key)

????key1 = CStr(arr(i, 2))

???????

????If Not dict(key).Exists(key1) Then

??????dict(key)(key1) = CStr(arr(i, 3))

????End If

??Next i

???

??Dim brr

??Dim j As Long

??Dim key2 As String

??Dim key3 As String

??Dim 新行 As Long

???

??brr = Sheets("輔材表").UsedRange.Value

??新行 = 2

??Sheets("長攤表").UsedRange.Rows.Delete

??For j = LBound(brr, 1) + 1 To UBound(brr, 1)

????key2 = CStr(brr(j, 1))

?????

????If dict.Exists(key2) Then

??????key3 = CStr(brr(j, 2))

???????

??????If dict(key2).Exists(key3) Then

????????If dict(key2)(key3) = CStr(brr(j, 3)) Then

??????????'數(shù)據(jù)滿足條件,需要存到【長攤表】中

??????????With Sheets("長攤表")

????????????.Cells(新行, 1).Value = "'" & brr(j, 1)

????????????.Cells(新行, 2).Value = "'" & brr(j, 2)

????????????.Cells(新行, 3).Value = "'" & brr(j, 3)

??????????End With

???????

??????????新行 = 新行 + 1

????????End If

??????End If

????End If

??Next j

End Sub

VBA——字典對象的常規(guī)用法和嵌套用法示例的評論 (共 條)

分享到微博請遵守國家法律
来安县| 古交市| 时尚| 南华县| 天峨县| 保康县| 綦江县| 昭通市| 宜川县| 易门县| 乐山市| 阳春市| 施秉县| 乐业县| 保康县| 莫力| 温泉县| 普兰县| 罗定市| 昌邑市| 长沙县| 湖州市| 高碑店市| 永寿县| 巩留县| 黄陵县| 北京市| 胶州市| 花莲市| 衡山县| 准格尔旗| 门头沟区| 石门县| 时尚| 固始县| 和静县| 长汀县| 大方县| 鄂托克旗| 沽源县| 莱芜市|