Need ideas for formula to display groups of data in certain format

Dman333

Board Regular
Joined
Sep 30, 2016
Messages
52
Office Version
  1. 365
Platform
  1. Windows
Hello All:

I'm looking for a formula that can go through a list of Items and Categories and then create a more readable output without having to list each item. Below I have Items and a category / bucket. I'd like to be able to have a formula that would show the results in the Desired Summary / Item #'s column like below. So instead of a list showing every number, it can display 1-3, 7, 17-20. There are a bunch of different formulas that do parts of this, I just can't figure out how to put them together so when you change an Item from Bucket A to Bucket B the Item #'s Summary will update.

Any help or ideas is greatly appreciated and thanks for the time.

Unique IdentifierCategoryDesired Summary
Item #BucketSummaryItem #'s
1ABucket A1-3, 7, 17-20
2ABucket B4-6, 8, 13
3ABucket C9-11
4BBucket D12, 14-16
5B
6B
7A
8B
9C
10C
11C
12D
13B
14D
15D
16D
17A
18A
19A
20A
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The following presentation can be done with Power Pivot by creating a measure.

Book1
DE
1BucketItems
2A1, 2, 3, 7, 17, 18, 19, 20
3B4, 5, 6, 8, 13
4C9, 10, 11
5D12, 14, 15, 16
Sheet1


Here is a link to a tutorial if this presentation is acceptable to you.

 
Upvote 0
Hi Dear,

I am not sure which MS Excel version you use, but in case you have recent versions, let me know if the below formula satisfy your requirement

Book1
ABCDE
1unique IdentifierCategoryDesired Summary
2Item #BucketSummaryItem #'s
31ABucket A1-2-3-7-17-18-19-20
42ABucket B4-5-6-8-13
53ABucket C9-10-11
64BBucket D12-14-15-16
75B
86B
97A
108B
119C
1210C
1311C
1412D
1513B
1614D
1715D
1816D
1917A
2018A
2119A
2220A
Sheet2
Cell Formulas
RangeFormula
E3:E6E3=TEXTJOIN("-",TRUE,FILTER($A$3:$A$22,(RIGHT(D3)=$B$3:$B$22)*1))


Regards
 
Upvote 0
Try This

VBA Code:
Sub certain_format()

Dim Cll As Range, Rng As Range
Dim Nary As Variant
Dim Arr As Variant
Dim Arr2 As Variant
   Set Rng = Sheets("Sheet1").Range("A1").CurrentRegion
   ReDim Nary(1 To Rng.Rows.Count, 1 To 2) As Variant

   TXT = ""
   T = ";Bucklet "
   For Each Cll In Rng
    If Cll.Row >= 3 Then
        If Cll.Column = 2 Then
            If InStr(1, TXT, T & Cll.Value, vbTextCompare) = 0 Then
            TXT = TXT & IIf(TXT <> "", Chr(10), "") & T & Cll.Value
                If Cll.Value = Cll.Offset(-1, 0).Value And Cll.Value <> Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, Cll.Value, Cll.Offset(0, -1).Value & "," & Cll.Value)
                ElseIf T & Cll.Value <> T & Cll.Offset(-1, 0).Value And T & Cll.Value = T & Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "-" & T & Cll.Value)
                ElseIf T & Cll.Value <> T & Cll.Offset(-1, 0).Value And T & Cll.Value <> T & Cll.Offset(1, 0).Value Then
                     TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "," & T & Cll.Value)
                End If
            Else
                If T & Cll.Value = T & Cll.Offset(-1, 0).Value And T & Cll.Value <> T & Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "," & T & Cll.Value)
                ElseIf T & Cll.Value <> T & Cll.Offset(-1, 0).Value And T & Cll.Value = T & Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "-" & T & Cll.Value)
                ElseIf T & Cll.Value <> T & Cll.Offset(-1, 0).Value And T & Cll.Value <> T & Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "," & T & Cll.Value)
                End If
            
            End If
            p = Cll.Value
        End If
    End If
   Next
   Arr = Split(Replace(TXT, ",;", ";"), Chr(10))
   For x = LBound(Arr) To UBound(Arr)
    Arr2 = Split(Arr(x), ";")
        For y = UBound(Arr2) To LBound(Arr2) Step -1
        
            Nary(x + 1, (UBound(Arr2) + 1 - y)) = "'" & Arr2(y) ' add apostrophes to avoid change format such as date Format if need
        Next
   Next
 Sheets("Sheet1").Range("D3").Resize(UBound(Arr) + 1, 2) = Nary
End Sub
Need ideas for formula to display groups of data in certain format.xlsm
ABCDE
1unique IdentifierCategoryDesired Summary
2Item #BucketSummaryItem #'s
31ABucklet A1-3,7,17-20
42ABucklet B4-6,8,13
53ABucklet C9-11
64BBucklet D12,14-16
75B
86B
97A
108B
119C
1210C
1311C
1412D
1513B
1614D
1715D
1816D
1917A
2018A
2119A
2220A
Sheet1
 
Upvote 0
Hi Dear,

I am not sure which MS Excel version you use, but in case you have recent versions, let me know if the below formula satisfy your requirement

Book1
ABCDE
1unique IdentifierCategoryDesired Summary
2Item #BucketSummaryItem #'s
31ABucket A1-2-3-7-17-18-19-20
42ABucket B4-5-6-8-13
53ABucket C9-10-11
64BBucket D12-14-15-16
75B
86B
97A
108B
119C
1210C
1311C
1412D
1513B
1614D
1715D
1816D
1917A
2018A
2119A
2220A
Sheet2
Cell Formulas
RangeFormula
E3:E6E3=TEXTJOIN("-",TRUE,FILTER($A$3:$A$22,(RIGHT(D3)=$B$3:$B$22)*1))


Regards
Rich (BB code):
The following presentation can be done with Power Pivot by creating a measure.

Book1
DE
1BucketItems
2A1, 2, 3, 7, 17, 18, 19, 20
3B4, 5, 6, 8, 13
4C9, 10, 11
5D12, 14, 15, 16
Sheet1


Here is a link to a tutorial if this presentation is acceptable to you.

Thanks for your time, but a pivot won't work for the end user.
Cheers
 
Upvote 0
Hi Dear,

I am not sure which MS Excel version you use, but in case you have recent versions, let me know if the below formula satisfy your requirement

Book1
ABCDE
1unique IdentifierCategoryDesired Summary
2Item #BucketSummaryItem #'s
31ABucket A1-2-3-7-17-18-19-20
42ABucket B4-5-6-8-13
53ABucket C9-10-11
64BBucket D12-14-15-16
75B
86B
97A
108B
119C
1210C
1311C
1412D
1513B
1614D
1715D
1816D
1917A
2018A
2119A
2220A
Sheet2
Cell Formulas
RangeFormula
E3:E6E3=TEXTJOIN("-",TRUE,FILTER($A$3:$A$22,(RIGHT(D3)=$B$3:$B$22)*1))


Regards
Thanks for this and your time. I like what you did here and this may end up being what I have to use. I was hoping to not have to list each number, but I'm not sure that can be done without VBA.
Cheers
 
Upvote 0
Try This

VBA Code:
Sub certain_format()

Dim Cll As Range, Rng As Range
Dim Nary As Variant
Dim Arr As Variant
Dim Arr2 As Variant
   Set Rng = Sheets("Sheet1").Range("A1").CurrentRegion
   ReDim Nary(1 To Rng.Rows.Count, 1 To 2) As Variant

   TXT = ""
   T = ";Bucklet "
   For Each Cll In Rng
    If Cll.Row >= 3 Then
        If Cll.Column = 2 Then
            If InStr(1, TXT, T & Cll.Value, vbTextCompare) = 0 Then
            TXT = TXT & IIf(TXT <> "", Chr(10), "") & T & Cll.Value
                If Cll.Value = Cll.Offset(-1, 0).Value And Cll.Value <> Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, Cll.Value, Cll.Offset(0, -1).Value & "," & Cll.Value)
                ElseIf T & Cll.Value <> T & Cll.Offset(-1, 0).Value And T & Cll.Value = T & Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "-" & T & Cll.Value)
                ElseIf T & Cll.Value <> T & Cll.Offset(-1, 0).Value And T & Cll.Value <> T & Cll.Offset(1, 0).Value Then
                     TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "," & T & Cll.Value)
                End If
            Else
                If T & Cll.Value = T & Cll.Offset(-1, 0).Value And T & Cll.Value <> T & Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "," & T & Cll.Value)
                ElseIf T & Cll.Value <> T & Cll.Offset(-1, 0).Value And T & Cll.Value = T & Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "-" & T & Cll.Value)
                ElseIf T & Cll.Value <> T & Cll.Offset(-1, 0).Value And T & Cll.Value <> T & Cll.Offset(1, 0).Value Then
                    TXT = Replace(TXT, T & Cll.Value, Cll.Offset(0, -1).Value & "," & T & Cll.Value)
                End If
           
            End If
            p = Cll.Value
        End If
    End If
   Next
   Arr = Split(Replace(TXT, ",;", ";"), Chr(10))
   For x = LBound(Arr) To UBound(Arr)
    Arr2 = Split(Arr(x), ";")
        For y = UBound(Arr2) To LBound(Arr2) Step -1
       
            Nary(x + 1, (UBound(Arr2) + 1 - y)) = "'" & Arr2(y) ' add apostrophes to avoid change format such as date Format if need
        Next
   Next
Sheets("Sheet1").Range("D3").Resize(UBound(Arr) + 1, 2) = Nary
End Sub
Need ideas for formula to display groups of data in certain format.xlsm
ABCDE
1unique IdentifierCategoryDesired Summary
2Item #BucketSummaryItem #'s
31ABucklet A1-3,7,17-20
42ABucklet B4-6,8,13
53ABucklet C9-11
64BBucklet D12,14-16
75B
86B
97A
108B
119C
1210C
1311C
1412D
1513B
1614D
1715D
1816D
1917A
2018A
2119A
2220A
Sheet1
OK Dossfm0q - This is really slick. I'm not much of a coder, but I was kind of able to follow how you did this. Thanks a ton for taking the time on this - this does exactly what I wanted. I just need to check with the end-user and see if their ok having to execute the code every time they make a change. This was just an example. In practice, the workbook has about 30 sheets that would have to run the code individually or alter the code to go through the entire workbook, which I know isn't hard to do. I'm likely to end up using the textjoin method above and stay away from vba for this user.

Thanks for all your time and effort on this - truly appreciated.
Cheers.
 
Upvote 0
I'm guessing you didn't like the Power Pivot solution. No comments about it? Afraid to expand your horizons? Feedback to people who are trying to help is imperative in these forums. Good or Bad we want it.
 
Upvote 0
I'm likely to end up using the textjoin method above and stay away from vba for this user
If you are wanting a formula solution and have TEXTJOIN, then you may also consider this which gives the format you asked for.
If you do not have the UNIQUE function then you can use the formulas in column G in column D instead.

BTW, please update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) you are using, and therefore what functions you have available. (Don’t forget to scroll down & ‘Save’)

21 02 07.xlsm
ABCDEFG
1Item #BucketSummaryItem #'sItem #'s
21AA1-3, 7, 17-20A
32AB4-6, 8, 13B
43AC9-11C
54BD12, 14-16D
65B  
76B  
87A
98B
109C
1110C
1211C
1312D
1413B
1514D
1615D
1716D
1817A
1918A
2019A
2120A
22
Sheet2 (2)
Cell Formulas
RangeFormula
D2:D5D2=UNIQUE(B2:B21)
E2:E7E2=IF(D2="","",SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(TRIM(CONCAT(IF(B$2:B$21=D2,IF(B$1:B$20<>D2,A$2:A$21,IF(B$3:B$22<>D2,A$2:A$21," ")),",")))," ","-"),","," "))," ",", "))
G2:G7G2=IFERROR(INDEX($B$2:$B$21,MATCH(0,INDEX(COUNTIF($G$1:G1,$B$2:$B$21)+(B$2:B$21=""),0),0)),"")
Dynamic array formulas.
 
Upvote 0
Solution
I'm guessing you didn't like the Power Pivot solution. No comments about it? Afraid to expand your horizons? Feedback to people who are trying to help is imperative in these forums. Good or Bad we want it.
Apologies - I thought I did respond but apparently skipped over it. Thanks for your time, but the end-user isn't familiar with how pivot tables work and it would need to constantly be refreshed. There's also a lot of other things going on in the table. The example was just a simplified version of what I'm doing. Thanks again for your time. I work with Pivots all the time and love them for certain things.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,688
Members
448,978
Latest member
rrauni

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