test已刪文
Sub MatchAndSumData()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long, j As Long
Dim matchValueA As Variant, matchValueB As Variant
Dim sumValue As Double
' 設置分頁
Set ws = Worksheets("Sheet1") ' 替換為你的工作表名稱
' 獲取 A 列的最後一行
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' 遍歷 A 和 B 列的每一行
For i = 2 To 65 ' A 和 B 列固定64行數據,從第2行開始到第65行
matchValueA = ws.Cells(i, 1).Value ' A 列數據
matchValueB = ws.Cells(i, 2).Value ' B 列數據
sumValue = 0 ' 初始化 sumValue
' 遍歷 F 和 G 列,找出匹配的行
For j = 2 To lastRow
If ws.Cells(j, 6).Value = matchValueA And ws.Cells(j, 7).Value = mat
chValueB Then ' F 列和 G 列匹配
sumValue = sumValue + ws.Cells(j, 8).Value ' 將 H 列數據相加
End If
Next j
' 將結果顯示在 C 列中
ws.Cells(i, 3).Value = sumValue
Next i
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.141.252.228 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Test/M.1716879932.A.01D.html
討論串 (同標題文章)