Vba for sumif type function

tintin1012000

Board Regular
Joined
Apr 27, 2011
Messages
237
I Have a large amount of data across 2 worksheets
data in these sheets is like below. but it continues across the work sheet a few hundred columns
TestValueTestValue
function66acme55
build87function22
acme44acme77

I need to do a sum if type function

In Sheet 1 I have a list of all the possible tests in column A .
I need to find all occurrences of cell A2 in work sheets called Results1 and Results2 and return the sum of the cell directly to the right of the result

eg
acme would returrn sum(44 + 55 +77 )and so on
Ideally in VBA

Thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this

VBA Code:
Sub SumType()
  Dim i As Long, s As Long, lr As Long, lc As Long
  Dim j As Long, k As Long
  Dim dic As Object, sh1 As Worksheet, sh2 As Worksheet
  Dim sh As Variant, a As Variant, c As Variant
  
  Set sh1 = Sheets("Sheet1")
  Set dic = CreateObject("Scripting.Dictionary")
  sh = Array("Results1", "Results2")
  a = sh1.Range("A2", sh1.Range("A" & Rows.Count).End(3)).Value2
  ReDim b(1 To UBound(a))
  
  For i = 1 To UBound(a)
    dic(a(i, 1)) = Empty
  Next
  
  For s = 0 To UBound(sh)
    Set sh2 = Sheets(sh(s))
    lr = sh2.Range("A" & Rows.Count).End(3).Row
    lc = sh2.Cells(1, Columns.Count).End(1).Column
    c = sh2.Range("A2", sh2.Cells(lr, lc))
    For j = 1 To UBound(c, 2) Step 2
      For k = 1 To UBound(c, 1)
        dic(c(k, j)) = dic(c(k, j)) + c(k, j + 1)
      Next
    Next
    Erase c
  Next
  
  sh1.Range("B2").Resize(dic.Count).Value = Application.Transpose(dic.items)
End Sub
 
Upvote 0
Do you have texts instead of numbers or a cell with error?
How many rows do you have?
How many columns do you have?
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,108
Members
449,205
Latest member
ralemanygarcia

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