Sum a column based on one criteria

Pinkster69

New Member
Joined
Jun 19, 2012
Messages
48
Hi Guys,

I have been wrecking my head with the following! hope you guys can help?

I am trying to look for some VBA Code so that I can search multiple values in Column "A" based on the criteria in Textbox1 and SUM up the corresponding values in Column "B" based of course on the criteria in Textbox1 and display them in Textbox2.

For example if I have multiple Part Numbers in Column "A" and there is a lot of duplicates and the prices of those parts are in column "B". If for example I enter a Part Number in Textbox1 "552", the code will search column "A" for all the Part Numbers that are "552" and sum up the corresponding prices based on the Part Number "552" in column "B" and display this in Textbox2. The trigger for this would be a commandButton1.
Just as a note, there might be some blank cells in both columns so it would be great if the code could allow for this.

Thanks in advance!

Pinkster69
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Did you try the Sumif function with the correct arguments in VBA?

WorksheetFunction.Sumif(...,...,...)
 
Upvote 0
Hi Wigi,

Thanks so much for your reply!
I'm fairly a novice at VBA, can you elaborate on how it relates to my example?

regards

Pinkster69
 
Upvote 0
Hi Wigi,

Thanks so much for your reply!
I'm fairly a novice at <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym>, can you elaborate on how it relates to my example?

regards

Pinkster69
 
Upvote 0
Here's a simple example, names in column A and numbers in column B:

Code:
Sub test()
   MsgBox WorksheetFunction.SumIf(Range("A2:A5"), "wim", Range("B2:B5"))
End Sub
 
Upvote 0
Hi Wigi,

Wow! how simple is that! I was expecting a lot of code.

Worked out great, thank you so much

regards

Pinkster69
 
Upvote 0

Forum statistics

Threads
1,214,379
Messages
6,119,190
Members
448,874
Latest member
Lancelots

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