Take duplicate consecutive cell values and sum their offset?

lakaihigh

New Member
Joined
May 17, 2019
Messages
12
Good evening,

Generally I can figure most things out on my own but I seem to be struggling with this one.
Can anyone assist with a formula or vba code that can do the following:

I need to find consecutive duplicates in column (I) and get the sum of .offset(0,1) if .offset(0,2)="LTL"

To add reasoning and hopefully clarity to what I'm trying to accomplish; I have a set of Data with Locations and dates and unit totals. (Columns "I", "H", and "J" respectively). In order to know whether to consolidate them, the location must match, the dates must match, and the sum of units from column J must be > 1300. In the attached example, I have already changed font to red to indicate the individual locations would be consolidated as each set of locations has matching dates from column "H") And their total units sum above 1300. Currently I use an if(and(or formula in another column to check if the location and dates match and then I manually sum. So long story short I'm simply trying to combine all into one formula or script.

Example Image: (in this scenario I would need the sum of I2 to I4, the sum of I5 to I6, the sum of I7 to I8).

Any assistance would be greatly appreciated.
 

Attachments

  • example.png
    example.png
    35.7 KB · Views: 11

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.
try this:

mr excel questions 13.xlsm
HIJK
1LADLocation
22023-03-17City1698TRUE
32023-03-17City1791TRUE
42023-03-17City1646TRUE
52023-03-17City2561TRUE
62023-03-17City2573TRUE
72023-03-17City2770TRUE
82023-03-17City2565TRUE
92023-03-24City3625FALSE
102023-03-24City3638FALSE
112023-03-24City1350FALSE
122023-03-24City1606FALSE
132023-03-30City4643FALSE
142023-03-30City3794TRUE
152023-03-30City3562TRUE
Sheet7
Cell Formulas
RangeFormula
K2:K15K2=SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2)>1300
 
Upvote 0
Here the formula wrapped in an IF so you can see the sum, i'm showing zero if less than 1300, you can change that to a " " if you want to show blanks:

mr excel questions 13.xlsm
HIJKL
1LADLocation
22023-03-17City16982135
32023-03-17City17912135
42023-03-17City16462135
52023-03-17City25612469
62023-03-17City25732469
72023-03-17City27702469
82023-03-17City25652469
92023-03-24City36250
102023-03-24City36380
112023-03-24City13500
122023-03-24City16060
132023-03-30City46430
142023-03-30City37941356
152023-03-30City35621356
16
Sheet7
Cell Formulas
RangeFormula
K2:K15K2=IF(SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2)>1300,SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2),0)
 
Upvote 0
try this:

mr excel questions 13.xlsm
HIJK
1LADLocation
22023-03-17City1698TRUE
32023-03-17City1791TRUE
42023-03-17City1646TRUE
52023-03-17City2561TRUE
62023-03-17City2573TRUE
72023-03-17City2770TRUE
82023-03-17City2565TRUE
92023-03-24City3625FALSE
102023-03-24City3638FALSE
112023-03-24City1350FALSE
122023-03-24City1606FALSE
132023-03-30City4643FALSE
142023-03-30City3794TRUE
152023-03-30City3562TRUE
Sheet7
Cell Formulas
RangeFormula
K2:K15K2=SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2)>1300
This actually works perfectly except for one factor. This will result in "True" even on a single location which requires no consolidation. Example attached.
Is there a way to state that it is false if the location is not a consecutive duplicate? Even if not, this helps tremendously. If I could get it to a point where, it's only showing True on locations that actually contain consecutive duplicates I could simply use conditional formatting to automatically format my data. Currently I'm using a VBA script that I wrote that formats my data (not counting the sum). Then I was manually going back and summing them and removing formatting on ones that shouldn't be formatted. VBA Example for context:

Consolidate()
For Each cell In Sheets(1).Range("I2:I1000" & LastRow)

If (cell.Value = cell.Offset(1, 0).Value Or cell.Value = cell.Offset(-1, 0).Value) And (cell.Offset(, -1).Value = cell.Offset(-1, -1).Value Or cell.Offset(, -1).Value = cell.Offset(1, -1).Value) Then


cell.EntireRow.Interior.Color = 3

End If
Next cell
End Sub

Greatly appreciate the assistance!
 

Attachments

  • example2.png
    example2.png
    64 KB · Views: 6
Upvote 0
Here you go:
mr excel questions 13.xlsm
HIJK
1LADLocation
22023-03-17City16982135
32023-03-17City17912135
42023-03-17City16462135
52023-03-17City25612469
62023-03-17City25732469
72023-03-17City27702469
82023-03-17City25652469
92023-03-24City36250
102023-03-24City36380
112023-03-24City13500
122023-03-24City16060
132023-03-30City414000
142023-03-30City37941356
152023-03-30City35621356
Sheet7
Cell Formulas
RangeFormula
K2:K15K2=IF(AND(COUNTIFS($H$2:$H$15,H2,$I$2:$I$15,I2)>1, SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2)>1300 ),SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2),0)
 
Upvote 0
Solution
with counts and true/false:
mr excel questions 13.xlsm
HIJKL
1LADLocation
22023-03-17City16982135TRUE
32023-03-17City17912135TRUE
42023-03-17City16462135TRUE
52023-03-17City25612469TRUE
62023-03-17City25732469TRUE
72023-03-17City27702469TRUE
82023-03-17City25652469TRUE
92023-03-24City36250FALSE
102023-03-24City36380FALSE
112023-03-24City13500FALSE
122023-03-24City16060FALSE
132023-03-30City414000FALSE
142023-03-30City37941356TRUE
152023-03-30City35621356TRUE
Sheet7
Cell Formulas
RangeFormula
K2:K15K2=IF(AND(COUNTIFS($H$2:$H$15,H2,$I$2:$I$15,I2)>1, SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2)>1300 ),SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2),0)
L2:L15L2=AND(COUNTIFS($H$2:$H$15,H2,$I$2:$I$15,I2)>1, SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2)>1300 )
 
Upvote 0
Here you go:
mr excel questions 13.xlsm
HIJK
1LADLocation
22023-03-17City16982135
32023-03-17City17912135
42023-03-17City16462135
52023-03-17City25612469
62023-03-17City25732469
72023-03-17City27702469
82023-03-17City25652469
92023-03-24City36250
102023-03-24City36380
112023-03-24City13500
122023-03-24City16060
132023-03-30City414000
142023-03-30City37941356
152023-03-30City35621356
Sheet7
Cell Formulas
RangeFormula
K2:K15K2=IF(AND(COUNTIFS($H$2:$H$15,H2,$I$2:$I$15,I2)>1, SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2)>1300 ),SUMIFS($J$2:$J$15,$H$2:$H$15,H2,$I$2:$I$15,I2),0)
Absolutely perfect.
Appreciate your time so very much!
 
Upvote 0
if you have 365 or 2021 version of excel you can even get a filtered output. (You should update your profile to show which version as solutions will vary from version to version of excel).
 
Upvote 0
if you have 365 or 2021 version of excel you can even get a filtered output. (You should update your profile to show which version as solutions will vary from version to version of excel).
Thank you, I will do that. Appreciate your time immensely.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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