簡體   English   中英

匹配列中的字符串並對相應的行求和

[英]Match string in column and sum corresponding rows

我有這個問題,我試圖用 VBA 解決。

桌子

表格示例

工作簿中只有一張工作表。

預期解決方案

我正在嘗試對A 列執行字符串搜索,如果它是 A75X (其中 X 是任意數字),我想在列 C下總結相應的 A75X 值,並將 A75 列 C 替換為空白價值。

預計 Output

預期產出

在新的 VBA 模塊中試試這個:

Sub CalculateFinancials()
        Dim aCells As Range
        Dim aCell As Range
        Dim cellValue As String
        Dim foreignCurrency As Double
        Dim nationalCurrency As Double

        Set aCells = Range("A:A")

        For Each aCell In aCells
            cellValue = aCell.Value
            If InStr(cellValue, "A75") <> 0  And cellValue <> "A75" Then
                foreignCurrency = foreignCurrency + Cells(aCell.Row, 3)
            End If
            If InStr(cellValue, "A71") <> 0  And cellValue <> "A71" Then
                nationalCurrency = nationalCurrency + Cells(aCell.Row, 3)
            End If
        Next aCell
        Cells(13, 3) = foreignCurrency
        Cells(4, 3) = nationalCurrency
    End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM