Split Records

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this data,

Fixed FTTH CBU Tech Compliants V1.xlsm
BCD
24Node*+Root CauseTicket Number+
25218-00_SAFAKH00OL0Access-Uplink issuePR00035914963
26PR00035915931
27Dark FiberPR00035913520
28PR00035914983
29PR00035916061
30PR00035917254
31PR00035920093
32MDTPR00035931421
33PR00035931520
34PR00035933798
35PR00035933799
36PR00035933811
37116-42_NFELRDAAOLKMan MadePR00035951924
38111-00_HTYNRD00OL5MDTPR00035909693
39PR00035923231
40Trans MediaPR00035963757
41116-42_NFELRDAAOT1Trans MediaPR00035967382
OLT2


and I have this code

VBA Code:
Sub split_recordsOLT2()
  Dim dic As Object
  Dim nCol As Long, nRow As Long, i As Long
  Dim a As Variant, b As Variant
 
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '''''
 ''''' OLT2
 '''''
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
  Set dic = CreateObject("Scripting.Dictionary")
  a = Range("C25", Range("D" & Rows.Count).End(3)).Value
  ReDim b(1 To UBound(a, 1), 1 To 100)
 
  For i = 1 To UBound(a, 1)
    If Not dic.exists(a(i, 1)) Then
      dic(a(i, 1)) = i
      nCol = 1
    Else
      nCol = nCol + 1
    End If
    b(dic(a(i, 1)), nCol) = a(i, 2)
  Next
 
  Range("E25").Resize(UBound(b, 1), UBound(b, 2)).Value = b
End Sub

but I am looking for this output, any modification on the code.

Fixed FTTH CBU Tech Compliants V1.xlsm
BCDEFGHI
24Node*+Root CauseTicket Number+Output1Output2Output3Output4Output5
25218-00_SAFAKH00OL0Access-Uplink issuePR00035914963PR00035914963PR00035915931
26PR00035915931
27Dark FiberPR00035913520PR00035913520PR00035914983PR00035916061PR00035917254PR00035920093
28PR00035914983
29PR00035916061
30PR00035917254
31PR00035920093
32MDTPR00035931421PR00035931421PR00035931520PR00035933798PR00035933799PR00035933811
33PR00035931520
34PR00035933798
35PR00035933799
36PR00035933811
37116-42_NFELRDAAOLKMan MadePR00035951924PR00035951924
38111-00_HTYNRD00OL5MDTPR00035909693PR00035909693PR00035923231
39PR00035923231
40Trans MediaPR00035963757PR00035963757
41116-42_NFELRDAAOT1Trans MediaPR00035967382PR00035967382
OLT2
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Assuming the data starts in A1

VBA Code:
Sub jec()
 Dim ar, j As Long, y As Long
 With Cells(1).CurrentRegion.Resize(, 4)
  ar = .Value
  For j = 2 To UBound(ar)
   If ar(j, 2) <> "" Then
     ar(j, 4) = ar(j, 3)
     y = j
   ElseIf ar(j, 2) = "" Then
     ar(y, 4) = ar(y, 4) & "|" & ar(j, 3)
   End If
  Next
  .Value = ar
  .Columns(4).TextToColumns Range("D1"), 1, , , , , , , 1, "|"
 End With
End Sub
 
Upvote 0
Assuming the data starts in A1

VBA Code:
Sub jec()
 Dim ar, j As Long, y As Long
 With Cells(1).CurrentRegion.Resize(, 4)
  ar = .Value
  For j = 2 To UBound(ar)
   If ar(j, 2) <> "" Then
     ar(j, 4) = ar(j, 3)
     y = j
   ElseIf ar(j, 2) = "" Then
     ar(y, 4) = ar(y, 4) & "|" & ar(j, 3)
   End If
  Next
  .Value = ar
  .Columns(4).TextToColumns Range("D1"), 1, , , , , , , 1, "|"
 End With
End Sub
by any way can you modify this code, as my data don't start from A1 but it starts from B25 please ref my post1 here i have mention "I have this data," B24 is header
 
Upvote 0
You could try

VBA Code:
Sub jec()
 Dim ar, j As Long, y As Long
 With [B24].CurrentRegion.Resize(, 4)
  ar = .Value
  For j = 2 To UBound(ar)
   If ar(j, 2) <> "" Then
     ar(j, 4) = ar(j, 3)
     y = j
   ElseIf ar(j, 2) = "" Then
     ar(y, 4) = ar(y, 4) & "|" & ar(j, 3)
   End If
  Next
  .Value = ar
  .Columns(4).TextToColumns [E25], 1, , , , , , , 1, "|"
 End With
End Sub
 
Upvote 0
You could try

VBA Code:
Sub jec()
 Dim ar, j As Long, y As Long
 With [B24].CurrentRegion.Resize(, 4)
  ar = .Value
  For j = 2 To UBound(ar)
   If ar(j, 2) <> "" Then
     ar(j, 4) = ar(j, 3)
     y = j
   ElseIf ar(j, 2) = "" Then
     ar(y, 4) = ar(y, 4) & "|" & ar(j, 3)
   End If
  Next
  .Value = ar
  .Columns(4).TextToColumns [E25], 1, , , , , , , 1, "|"
 End With
End Sub
It is giving me the desired output, but in this line
VBA Code:
  .Columns(4).TextToColumns [E25], 1, , , , , , , 1, "|"


Giving me error as 1004 (screen shot)
 
Upvote 0
Change the E25 to E24 ;)

your idea of putting "|" is very good, but not sure why it is giving me error 1004

on line
VBA Code:
   .Columns(4).TextToColumns [E24], 1, , , , , , , 1, "|"

Book2
BCDE
24Node*+Root CauseTicket Number+
25218-00_SAFAKH00OL0Access-Uplink issuePR00035914963PR00035914963|PR00035915931
26PR00035915931
27Dark FiberPR00035913520PR00035913520|PR00035914983|PR00035916061|PR00035917254|PR00035920093
28PR00035914983
29PR00035916061
30PR00035917254
31PR00035920093
32MDTPR00035931421PR00035931421|PR00035931520|PR00035933798|PR00035933799|PR00035933811
33PR00035931520
34PR00035933798
35PR00035933799
36PR00035933811
37116-42_NFELRDAAOLKMan MadePR00035951924PR00035951924
38111-00_HTYNRD00OL5MDTPR00035909693PR00035909693|PR00035923231
39PR00035923231
40Trans MediaPR00035963757PR00035963757
41116-42_NFELRDAAOT1Trans MediaPR00035967382PR00035967382
Sheet1
 
Upvote 0
It was @JEC's idea not mine and quite a neat way of keeping the code to a minimum.
It is working fine for me using [B24] and [E24] so there has to be something about your data.

If you add the line in blue after the with statement what does it show in the immediate window ?

Rich (BB code):
 With [B24].CurrentRegion.Resize(, 4)
  Debug.Print .Address
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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