test已刪文

看板Test作者 (冠宇哥)時間1年前 (2024/05/28 15:05), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2303/2567 (看更多)
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
文章代碼(AID): #1cLO8y0T (Test)
討論串 (同標題文章)
完整討論串 (本文為第 2303 之 2567 篇):
1
1
2天前, 12/22
3天前, 12/20
1
1
5天前, 12/18
1
1
1
2
6天前, 12/17
1
1
1周前, 12/12
0
1
2周前, 12/04
文章代碼(AID): #1cLO8y0T (Test)