回覆列表
  • 1 # 使用者3048347432725

    VBA的話很簡單。字典讀入資料,再匹配即可。

    Sub test()

    With Sheet1

    arr = Application.Transpose(Sheet1.Range("d4:d68"))

    Set d = CreateObject("scripting.dictionary")

    For i = 10 To 23

    For m = 1 To UBound(arr)

    d(arr(m)) = d(arr(m)) + .Cells(m + 3, i)

    Next m

    it = d.items

    "將取出的東西寫入表格2裡面

    For n = 3 To 500 "取出月份行數,作為迴圈起始點

    If Sheet2.Range("a" & n) = "2018." & .Cells(3, i) Then: a = Sheet2.Range("a" & n).Row

    If Sheet2.Range("a" & n) = "2018." & .Cells(3, i + 1) Then: b = Sheet2.Range("a" & n).Row

    Next n

    For r = a To b

    num = Sheet2.Cells(r, "c")

    If num <> "" Then

    Sheet2.Cells(r, "d") = d(num)

    Else

    End If

    Next r

    Next

    End With

    End Sub

  • 中秋節和大豐收的關聯?
  • 吉利和哈佛兩個牌子的汽車油耗如何?