Line Break after each unique entry

garypea123

Board Regular
Joined
Mar 16, 2020
Messages
221
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon,

Unfortunately I do not have XLSBB on computer (due to restrictions)

In C4 I have my list of numbers

In D4 I would like a formula which will look at the data from C4# and create a break after each unique entry.

Have a great weekend all :)

UNIQUE BREAK.PNG
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
  1. A recent Lambda function I submitted might help as a new approach:

  2. A function that takes C4:C12 as the source range:
    Excel Formula:
    =LET(range, C4:C12,
           rows, ROWS(range)*2,
          row, SEQUENCE(rows),
          IF(MOD(row,2)=1,INDEX(range,(row+1)/2),""))
    Book1.xlsm
    CD
    438672923867292
    54854915
    648549154854915
    71692828
    834495034854915
    93449503
    107543471692828
    114501923076
    1245019230763449503
    13
    143449503
    15
    16754347
    17
    184501923076
    19
    204501923076
    21
    Sheet3
    Cell Formulas
    RangeFormula
    D4:D21D4=LET(range, C4:C12, rows, ROWS(range)*2, row, SEQUENCE(rows), IF(MOD(row,2)=1,INDEX(range,(row+1)/2),""))
    Dynamic array formulas.
  3. A User Defined Function that returns an array that you can copy and paste into a standard module, and use in the cell by providing the range (this could be also turned to a macro instead of UDF):
    VBA Code:
    Function BlankAtEvenRow(rng As Range)
    Dim cll As Range
    Dim i As Long
    ReDim ret(1 To rng.Rows.Count * 2)  
        For Each cll In rng.Cells
            i = 2 * (cll.Row - rng.Row + 1) - 1
            ret(i) = cll.Value
            ret(i + 1) = ""
        Next cll
        BlankAtEvenRow = WorksheetFunction.Transpose(ret)  
    End Function
    Book1.xlsm
    CD
    438672923867292
    54854915
    648549154854915
    71692828
    834495034854915
    93449503
    107543471692828
    114501923076
    1245019230763449503
    13
    143449503
    15
    16754347
    17
    184501923076
    19
    204501923076
    21
    Sheet3
    Cell Formulas
    RangeFormula
    D4:D21D4=BlankAtEvenRow(C4:C12)
    Dynamic array formulas.
 
Upvote 0
My take on this
Fluff.xlsm
ABCD
1
2
3
438672923867292
54854915
648549154854915
716928284854915
83449503
934495031692828
10754347
1145019230763449503
1245019230763449503
13
14754347
15
164501923076
174501923076
Main
Cell Formulas
RangeFormula
D4:D17D4=LET(u,UNIQUE(C4:C12),DROP(DROP(REDUCE("",u,LAMBDA(a,b,VSTACK(a,FILTER(C4:C12,C4:C12=b),""))),1),-1))
Dynamic array formulas.
 
Upvote 0
Ah! I just saw the "each unique entry" in the original question. I think I was too lazy looking at the screenshot only :)

Thanks, @Fluff!
 
Upvote 0
Maybe this works

VBA Code:
Sub jec()
 Dim cl
 With CreateObject("scripting.dictionary")
    For Each cl In Range("C5", Range("C" & Rows.Count).End(xlUp))
      If Not .exists(cl.Value) Then .Item(cl.Value) = .Item(cl.Value) & IIf(.exists(cl.Value), ",", "") & cl.Row & ":" & cl.Row
    Next
    Range(Join(.items, ",")).Insert
 End With
End Sub
 
Last edited:
Upvote 0
My take on this
Fluff.xlsm
ABCD
1
2
3
438672923867292
54854915
648549154854915
716928284854915
83449503
934495031692828
10754347
1145019230763449503
1245019230763449503
13
14754347
15
164501923076
174501923076
Main
Cell Formulas
RangeFormula
D4:D17D4=LET(u,UNIQUE(C4:C12),DROP(DROP(REDUCE("",u,LAMBDA(a,b,VSTACK(a,FILTER(C4:C12,C4:C12=b),""))),1),-1))
Dynamic array formulas.
I think I may be using an excel version (Microsoft® Excel® for Microsoft 365 MSO) which is too old as it does not like the formula.

I am getting a #NAME? Result
 
Upvote 0
Maybe this works

VBA Code:
Sub jec()
 Dim cl
 With CreateObject("scripting.dictionary")
    For Each cl In Range("C5", Range("C" & Rows.Count).End(xlUp))
      If Not .exists(cl.Value) Then .Item(cl.Value) = .Item(cl.Value) & IIf(.exists(cl.Value), ",", "") & cl.Row & ":" & cl.Row
    Next
    Range(Join(.items, ",")).Insert
 End With
End Sub
I have tried this, but it gives a blank after each item, rather after each unique line.

SNIP.PNG
 
Upvote 0
It works fine here. The code is bases on column C.
In your picture its column D. Maybe change this line to

VBA Code:
For Each cl In Range("D5", Range("D" & Rows.Count).End(xlUp))
 
Upvote 0
It works fine here. The code is bases on column C.
In your picture its column D. Maybe change this line to

VBA Code:
For Each cl In Range("D5", Range("D" & Rows.Count).End(xlUp))

Apologies, I was actually using the VBA from Smogcur.

Yes, I can see that your one works for that purpose. However, I was trying to avoid excel creating / inserting new rows as this will affect other formulas.

In an ideal work I had the raw data in Column C, and then I would create some kind of filter which would take this raw data and generate (In column D) the same table but with breaks after each unique entry. However, I would like the raw data to remain as it was.
 
Upvote 0
I am getting a #NAME? Result
Ok, how about
Excel Formula:
=LET(u,UNIQUE(C4:C12),DROP(DROP(REDUCE("",u,LAMBDA(a,b,LET(f,FILTER(C4:C12,C4:C12=b),r,ROWS(a),s,SEQUENCE(r+ROWS(f)+1),IFERROR(IF(s<=r,a,INDEX(f,s-r)),"")))),1),-1))
 
Upvote 0
Solution

Forum statistics

Threads
1,215,472
Messages
6,125,011
Members
449,204
Latest member
tungnmqn90

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