Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7804253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:51:16+00:00 2026-06-02T01:51:16+00:00

OK, I have a simple problem that I need help with in a VBA

  • 0

OK, I have a simple problem that I need help with in a VBA Macro. I have an excel sheet that looks like this…

Product #     Count
101              1
102              1
101              2
102              2
107              7
101              4
101              4
189              9

I need a macro that adds up the “count” column based on the Product Number Column. I want it to over all look like this after I am done…

Product #    Count
101              7
102              7
107              7
189              9

I am an amiture to VBA so I would love any help I can get.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:51:18+00:00Added an answer on June 2, 2026 at 1:51 am

    Assuming the data is in columns A and B, you can do it with a formula:

    =SUMIF(A:A,101,B:B)
    

    Or if you put 101 in C1:

    =SUMIF(A:A,C1,B:B)
    

    EDIT

    However if you still require VBA, here is my (quick and dirty) proposal – I use a dictionary to keep track of the sum for each item.

    Sub doIt()
    
      Dim data As Variant
      Dim i As Long
      Dim countDict As Variant
      Dim category As Variant
      Dim value As Variant
    
      Set countDict = CreateObject("Scripting.Dictionary")
    
      data = ActiveSheet.UsedRange 'Assumes data is in columns A/B
    
      'Populate the dictionary: key = category / Item = count
      For i = LBound(data, 1) To UBound(data, 1)
        category = data(i, 1)
        value = data(i, 2)
        If countDict.exists(category) Then
          countDict(category) = countDict(category) + value 'if we have already seen that category, add to the total
        Else
          countDict(category) = value 'first time we find that category, create it
        End If
      Next i
    
      'Copy dictionary into an array
      ReDim data(1 To countDict.Count, 1 To 2) As Variant
    
      Dim d As Variant
      i = 1
      For Each d In countDict
        data(i, 1) = d
        data(i, 2) = countDict(d)
        i = i + 1
      Next d
    
      'Puts the result back in the sheet in column D/E, including headers
      With ActiveSheet
        .Range("D1").Resize(UBound(data, 1), UBound(data, 2)) = data
      End With
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a simple problem: I have a WF4 activity that guides the
I have a likely simple problem that I need help with. I have two
I have a coding/maths problem that I need help translating into C#. It's a
I need some help with this one.... I have this simple model: public class
I have a problem that seems like there should be a simple solution but
i have a simple problem with that fetch_array. i like to read out x1
I have the following simple problem that I'd like to use to experiment with
I have very simple problem that I can't solve. I need to do something
I have a simple problem that i cannot solve. I have a dictionary: aa
I have a very simple C# DataTable problem that I cannot seem to wrap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.