Adding a range based on criteria

Jtbuman

New Member
Joined
Jun 29, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I'm having some trouble coming up with a code that will work for this. Any help would be greatly appreciated!!

I need something like..

If the cell in column D shows "Setup" add the cells in column L, going up, but stop adding when the cell in column D shows "Setup" again. Then put that total in column M one row above the row with "Setup".



1624984192576.png
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,383
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Sub jtbuman()
   Dim Ar As Areas
   Dim Rng As Range
   
   With Range("D2", Range("D" & Rows.Count).End(xlUp))
      .Replace "Setup", "=xxxSetup", xlWhole, , False, , False, False
      Set Ar = .SpecialCells(xlConstants).Offset(, 8).Areas
      .Replace "=xxxSetup", "Setup", xlWhole, , False, , False, False
   End With
   For Each Rng In Ar
      Rng.Offset(-1, 1).Resize(1).Formula = "=sum(" & Rng.Address & ")"
   Next Rng
End Sub
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,383
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,141,309
Messages
5,705,675
Members
421,404
Latest member
Mikecollo

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
Top