Sum a Row based on found value in a column

Eriktoinfinity

New Member
Joined
Apr 1, 2014
Messages
6
I need to find a specific value in a column and then sum a specific range in that row belonging to the value, but the column location changes whenever someone inputs their data for their specific project, even though the value doesn't. Is this possible in a formula or would that require a macro?

Example: my value is the category number and I need to find category 5 (row 6 for store 1) and sum up the sales in the 3rd, 4th and 5th columns of that row. The location of category 5 changes to row 5 for store 2.

StoreCategoryJan SalesFeb SalesMar Sales
11100010001000
12200020002000
13300030003000
14400040004000
15500050005000
16600060006000
StoreCategoryJan SalesFeb SalesMar Sales
21100010001000
22200020002000
24400040004000
25500050005000
27700070007000
28800080008000

<tbody>
</tbody>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Assuming your table starts in A1, try something like:

=SUM(INDEX(B1:E7,MATCH(5,B1:B7,0),2):INDEX(B1:E7,MATCH(5,B1:B7,0),4))

Ranges would need to be adjusted for your actual data.
 
Upvote 0
Hi Erik...

Maybe something like this for a VBA solution.

Using input boxes to identify the store/category, with results posted in columns K & L.

With a tiny bit of tweaking, we can go to entering the store in G1, category in G2 and a message box for the total.

Howard

Code:
Option Explicit

Sub My_Store_No_Sum()
Dim i As Long, ii As Long
Dim c As Range, sSum As Range
Dim OneRng As Range

Set OneRng = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)

i = Application.InputBox("Enter Store No.", _
    "Col A Finder", , , , , , 2)
ii = Application.InputBox("Enter Category.", _
    "Col A Finder", , , , , , 2)

'i = Range("G1")
'ii = Range("G2")

For Each c In OneRng
  If c = i And c.Offset(, 1) = ii Then
    Set sSum = c.Offset(, 2).Resize(1, 3)
    'MsgBox Application.WorksheetFunction.Sum(sSum)
  Range("K" & Rows.Count).End(xlUp)(2) = Application.WorksheetFunction.Sum(sSum)
  Range("L" & Rows.Count).End(xlUp)(2) = "Store - " & i & " Category - " & ii
  End If
Next

'[G1].Activate
End Sub
 
Upvote 0
Thanks, bbott! This is exactly what I needed. It didn't work until I changed the "2" and "4" in the index formulas to "1" and "3" as the index function only wanted the column number within the array, not within the worksheet. Thanks again!!!
 
Upvote 0
Thank you, L. Howard. I needed a formula over VBA, but I'll certainly save this as it might come in handy for something else I'm working on! Thanks again!
 
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,560
Members
449,237
Latest member
Chase S

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