sumif with text and number and special symbol

Vishaal

Well-known Member
Joined
Mar 16, 2019
Messages
533
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. Web
we want to do following

first we want to use unique value from sheet1!B1:B to Sheet2!B1

after that sum if condition match in Sheet2!C2
after that sum if condition if match in Sheet2!D2

query sheet
Book1
BCD
1CodeNoAmount
2847-19981450
3sde-feb-20234950
4sde/SEP/1998255674
5dfe-April-246587
6852-1998698
78754399310
89874608400
9909-198167987
10736212900
11dde-NOV-10756798
12ddf-DEC-197567999
13847-19985540
14sde-feb-20234950
15909-198133
Sheet1

Result Sheet
Book1
BCD
1CodeNoAmount
2847-19986990
3sde-feb-202381900
4sde/SEP/1998255674
5dfe-April-246587
6852-1998698
78754399310
89874608400
9909-198170990
10736212900
11dde-NOV-10756798
12ddf-DEC-197567999
Sheet2
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Power query
Book3
ABC
2847-19986990
3sde-feb-202381900
4sde/SEP/1998255674
5dfe-April-246587
6852-1998698
78754399310
89874608400
9909-198170990
10736212900
11dde-NOV-10756798
12ddf-DEC-197567999
Table1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type any}, {"No", Int64.Type}, {"Amount", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Code"}, {{"No", each List.Sum([No]), type nullable number}, {"Amount", each List.Sum([Amount]), type nullable number}})
in
    #"Grouped Rows"
 
Upvote 0
Thanks Kerryx

Can we do it through VBA

I will also check today, how to use power query
 
Upvote 0
More info here

 
Upvote 0
Not sure why you don't just use a pivot table but if you really need to stick with VBA see if this helps.

VBA Code:
Sub SummariseData()

    Dim shtSrc As Worksheet, shtOut As Worksheet
    Dim rngSrc As Range, rngOut As Range
    Dim arrSrc As Variant, arrOut As Variant
    Dim i As Long, rowOut As Long
    
    Dim dictData As Object, dictKey As String
    
    Set shtSrc = Worksheets("Sheet1")
    With shtSrc
        Set rngSrc = .Range("A2:C" & .Cells(Rows.Count, "A").End(xlUp).Row)
        arrSrc = rngSrc.Value2
    End With
    
    Set shtOut = Worksheets("Sheet2")
    With shtOut
        Set rngOut = .Range("A1")
        rngOut.CurrentRegion.Offset(1).ClearContents
        rngSrc.Resize(1).Offset(-1).Copy Destination:=rngOut
        ReDim arrOut(1 To UBound(arrSrc), 1 To UBound(arrSrc, 2))
    End With

    Set dictData = CreateObject("Scripting.dictionary")
    
    For i = 1 To UBound(arrSrc)
        dictKey = arrSrc(i, 1)
        If dictData.exists(dictKey) Then
            arrOut(dictData(dictKey), 2) = arrOut(dictData(dictKey), 2) + arrSrc(i, 2)
            arrOut(dictData(dictKey), 3) = arrOut(dictData(dictKey), 3) + arrSrc(i, 3)
        Else
            rowOut = rowOut + 1
            dictData(dictKey) = rowOut
            arrOut(rowOut, 1) = arrSrc(i, 1)
            arrOut(rowOut, 2) = arrSrc(i, 2)
            arrOut(rowOut, 3) = arrSrc(i, 3)
        End If
    Next i
    
    rngOut.Offset(1).Resize(rowOut, UBound(arrOut, 2)).Value2 = arrOut

End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top