Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Consolidation: Combining groups of identical items

I have four ranges of cells on separate rows. I want to be able to
consolidate groups of identical items from these rows into a list in a
column. In addition I need to sum the numbers associated with the
item (numbers are directly below the item in case that helps)

A visual simplification:

Col A Col B Col C Col D
R 1 apple apple apple pear
R 2 5.5 5.5 5.5 3
R 3
R 4 pear dog dog rabbit
R 5 3 5 5 6
R 6
R 7 apple apple apple apple
R 8 5.5 5.5 5.5 5.5
R 9
R 10 cat apple cat cat
R 11 2 5.5 2 2
R 12

Would consolidate by way of a macro (or perhaps a trick array
formula?) into:

Col A Col B
R 50 Item Sum
R 51 apple 16.5
R 52 pear 3
R 53 pear 3
R 54 dog 10
R 55 rabbit 6
R 56 apple 22
R 57 cat 2
R 58 apple 5.5
R 59 cat 4

Where one row ends in a item that is the same as the first item on the
next row (eg pear on rows 1 and 4) the item appears twice and is not
treated as a 'group'.

I appreciate that providing a complete solution would be a huge ask,
but I thought I'd throw it out there to see what advice I could get.
I've searched these newsgroups and have found valuable chunks of code
and useful formulae, but I have been unable to combine this to work
for my scenario.

Any words of wisdom are appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Consolidation: Combining groups of identical items

Jason,

Here's an example of how to do it (at least, it worked for me using your
sample tables)--I put the source table on Sheet "1" and the results table on
Sheet "2", each table starting in cell "A1":


Private rngItem As Range
Sub Consolidate()
x = 1
y = 0
Do
With Sheets("1")
y = y + 1
sItem = .Cells(x, y)
If sItem < Empty Then
nValue = .Cells(x + 1, y)
If sItem < OldItem Then ItemRange
rngItem.Value = sItem
rngItem.Offset(0, 1).Value = rngItem.Offset(0, 1).Value +
nValue
OldItem = sItem
Else
x = x + 3
y = 0
OldItem = ""
If .Cells(x, 1) = Empty Then Exit Do
End If
End With
Loop
End Sub
Sub ItemRange()
With Sheets("2")
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
Set rngItem = .Cells(LastRow + 1, 1)
End With
End Sub

HTH,
Shockley




"Jason" wrote in message
om...
I have four ranges of cells on separate rows. I want to be able to
consolidate groups of identical items from these rows into a list in a
column. In addition I need to sum the numbers associated with the
item (numbers are directly below the item in case that helps)

A visual simplification:

Col A Col B Col C Col D
R 1 apple apple apple pear
R 2 5.5 5.5 5.5 3
R 3
R 4 pear dog dog rabbit
R 5 3 5 5 6
R 6
R 7 apple apple apple apple
R 8 5.5 5.5 5.5 5.5
R 9
R 10 cat apple cat cat
R 11 2 5.5 2 2
R 12

Would consolidate by way of a macro (or perhaps a trick array
formula?) into:

Col A Col B
R 50 Item Sum
R 51 apple 16.5
R 52 pear 3
R 53 pear 3
R 54 dog 10
R 55 rabbit 6
R 56 apple 22
R 57 cat 2
R 58 apple 5.5
R 59 cat 4

Where one row ends in a item that is the same as the first item on the
next row (eg pear on rows 1 and 4) the item appears twice and is not
treated as a 'group'.

I appreciate that providing a complete solution would be a huge ask,
but I thought I'd throw it out there to see what advice I could get.
I've searched these newsgroups and have found valuable chunks of code
and useful formulae, but I have been unable to combine this to work
for my scenario.

Any words of wisdom are appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Consolidation: Combining groups of identical items

PS, You need to put the column labels "Item" and "Sum" in Cells "A1" and
"B1" on Sheet "2" before running the macro.

Shockley



"shockley" wrote in message
...
Jason,

Here's an example of how to do it (at least, it worked for me using your
sample tables)--I put the source table on Sheet "1" and the results table

on
Sheet "2", each table starting in cell "A1":


Private rngItem As Range
Sub Consolidate()
x = 1
y = 0
Do
With Sheets("1")
y = y + 1
sItem = .Cells(x, y)
If sItem < Empty Then
nValue = .Cells(x + 1, y)
If sItem < OldItem Then ItemRange
rngItem.Value = sItem
rngItem.Offset(0, 1).Value = rngItem.Offset(0, 1).Value +
nValue
OldItem = sItem
Else
x = x + 3
y = 0
OldItem = ""
If .Cells(x, 1) = Empty Then Exit Do
End If
End With
Loop
End Sub
Sub ItemRange()
With Sheets("2")
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
Set rngItem = .Cells(LastRow + 1, 1)
End With
End Sub

HTH,
Shockley




"Jason" wrote in message
om...
I have four ranges of cells on separate rows. I want to be able to
consolidate groups of identical items from these rows into a list in a
column. In addition I need to sum the numbers associated with the
item (numbers are directly below the item in case that helps)

A visual simplification:

Col A Col B Col C Col D
R 1 apple apple apple pear
R 2 5.5 5.5 5.5 3
R 3
R 4 pear dog dog rabbit
R 5 3 5 5 6
R 6
R 7 apple apple apple apple
R 8 5.5 5.5 5.5 5.5
R 9
R 10 cat apple cat cat
R 11 2 5.5 2 2
R 12

Would consolidate by way of a macro (or perhaps a trick array
formula?) into:

Col A Col B
R 50 Item Sum
R 51 apple 16.5
R 52 pear 3
R 53 pear 3
R 54 dog 10
R 55 rabbit 6
R 56 apple 22
R 57 cat 2
R 58 apple 5.5
R 59 cat 4

Where one row ends in a item that is the same as the first item on the
next row (eg pear on rows 1 and 4) the item appears twice and is not
treated as a 'group'.

I appreciate that providing a complete solution would be a huge ask,
but I thought I'd throw it out there to see what advice I could get.
I've searched these newsgroups and have found valuable chunks of code
and useful formulae, but I have been unable to combine this to work
for my scenario.

Any words of wisdom are appreciated.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting identical items in a column and returning the occurrences ExcelWizardImNot Excel Discussion (Misc queries) 3 March 27th 10 09:09 AM
Equally combining two unequal groups ph4nu Excel Worksheet Functions 2 August 21st 08 05:14 PM
Count unique items in groups GarToms Excel Worksheet Functions 2 August 24th 06 04:24 AM
how to group several items in different groups to be placed in a c Colin2u Excel Discussion (Misc queries) 1 July 31st 05 07:10 AM
Counting groups of similar items Jason[_30_] Excel Programming 11 June 23rd 04 12:58 AM


All times are GMT +1. The time now is 10:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"