Return in cell

DEllis

Active Member
Joined
Jun 4, 2009
Messages
350
Office Version
  1. 365
Platform
  1. Windows
Hello everyone. so I have a spreadsheet that looks like this
Numberdate/time
UPH0015429
UPH0015428
12/15/2024 20:39:16
UPH0015426
UPH0015425
01/05/2025 09:36:12

What I need is to have the number column take the bottom number out put it in a new line beneath the number and remove the return... so like this (note date and time for second number in cell is same as first)
NumberDate/time
UPH001542912/15/2024 20:39:16
UPH001542812/15/2024 20:39:16
UPH001542601/05/2025 09:36:12
UPH00154201/05/2025 09:36:12

I am okay if the data cannot align with the second number, but I do need the numbers separated right beneath each other. The issue I have is some lines there is no second number just one, so that line is okay.
 
Hello @ DEllis.
Maybe I didn't understand you, but here is a possible solution to your question using vba code.
VBA Code:
Option Explicit

Sub SplitCells()
    Dim j           As Long
    Dim valuesArr   As Variant
    Dim insertRow   As Long

    Dim ws          As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1")    ' Specify name of your worksheet

    Dim lastRow     As Long
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    Dim i           As Long
    i = 2    ' Let's start with the second row, if you have a different row, then change it
    Application.ScreenUpdating = False

    Do While i <= lastRow

        If ws.Cells(i, 1).Value <> "" Then
            valuesArr = Split(ws.Cells(i, 1).Value, vbLf)

            If UBound(valuesArr) > 0 Then
                ws.Cells(i, 1).Value = Trim(valuesArr(0))
                insertRow = i + 1

                For j = 1 To UBound(valuesArr)
                    ws.Rows(insertRow).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                    ws.Cells(insertRow, 1).Value = Trim(valuesArr(j))
                    ws.Cells(insertRow, 2).Value = ws.Cells(i, 2).Value

                    insertRow = insertRow + 1
                    lastRow = lastRow + 1
                Next j

            End If

        End If

        i = i + 1
    Loop

    Set ws = Nothing
    Application.ScreenUpdating = True
    MsgBox "Cell splitting complete!", vbInformation
End Sub
I hope I understood you correctly and was able to help you. Good luck.
 
Upvote 0
Is this what you are after?

25 02 21.xlsm
ABCDE
1Numberdate/timeNumberdate/time
2UPH0015429 UPH001542815/12/2024 20:39:16UPH001542915/12/2024 20:39:16
3UPH001542712/12/2024 20:02:25UPH001542815/12/2024 20:39:16
4UPH0015426 UPH001542505/01/2025 09:36:12UPH001542712/12/2024 20:02:25
5UPH001542605/01/2025 09:36:12
6UPH001542505/01/2025 09:36:12
new lines
Cell Formulas
RangeFormula
D2:E6D2=LET(n,TEXTSPLIT(TEXTJOIN(CHAR(10),,A2:A4),,CHAR(10)),HSTACK(n,VLOOKUP("*"&n&"*",A2:B4,2,0)))
Dynamic array formulas.
 
Upvote 0
Is this what you are after?

25 02 21.xlsm
ABCDE
1Numberdate/timeNumberdate/time
2UPH0015429 UPH001542815/12/2024 20:39:16UPH001542915/12/2024 20:39:16
3UPH001542712/12/2024 20:02:25UPH001542815/12/2024 20:39:16
4UPH0015426 UPH001542505/01/2025 09:36:12UPH001542712/12/2024 20:02:25
5UPH001542605/01/2025 09:36:12
6UPH001542505/01/2025 09:36:12
new lines
Cell Formulas
RangeFormula
D2:E6D2=LET(n,TEXTSPLIT(TEXTJOIN(CHAR(10),,A2:A4),,CHAR(10)),HSTACK(n,VLOOKUP("*"&n&"*",A2:B4,2,0)))
Dynamic array formulas.
Hi there, I put this formula into D2 and in E2 I get Invalid cell reference error. What you showed is exactly what I need, but I can't seem to make it work in my spreadsheet.
 
Upvote 0
Hi there, I put this formula into D2 and in E2 I get Invalid cell reference error. What you showed is exactly what I need, but I can't seem to make it work in my spreadsheet.
Thank you
Hello @ DEllis.
Maybe I didn't understand you, but here is a possible solution to your question using vba code.
VBA Code:
Option Explicit

Sub SplitCells()
    Dim j           As Long
    Dim valuesArr   As Variant
    Dim insertRow   As Long

    Dim ws          As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1")    ' Specify name of your worksheet

    Dim lastRow     As Long
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    Dim i           As Long
    i = 2    ' Let's start with the second row, if you have a different row, then change it
    Application.ScreenUpdating = False

    Do While i <= lastRow

        If ws.Cells(i, 1).Value <> "" Then
            valuesArr = Split(ws.Cells(i, 1).Value, vbLf)

            If UBound(valuesArr) > 0 Then
                ws.Cells(i, 1).Value = Trim(valuesArr(0))
                insertRow = i + 1

                For j = 1 To UBound(valuesArr)
                    ws.Rows(insertRow).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                    ws.Cells(insertRow, 1).Value = Trim(valuesArr(j))
                    ws.Cells(insertRow, 2).Value = ws.Cells(i, 2).Value

                    insertRow = insertRow + 1
                    lastRow = lastRow + 1
                Next j

            End If

        End If

        i = i + 1
    Loop

    Set ws = Nothing
    Application.ScreenUpdating = True
    MsgBox "Cell splitting complete!", vbInformation
End Sub
I hope I understood you correctly and was able to help you. Good luck.
Thank you
 
Upvote 0
Note that Peter's suggestion won't work if you have repeated values in Number column. An alternative in G and H.
Book2
ABCDEFGH
1Numberdate/timeNumberdate/timeNumberdate/time
2UPH0015429 UPH001542812/15/2024 20:39:16UPH001542912/15/2024 20:39:16UPH001542912/15/2024 20:39:16
3UPH001542712/12/2024 20:02:25UPH001542812/15/2024 20:39:16UPH001542812/15/2024 20:39:16
4UPH0015429 UPH00154251/5/2025 9:36:12UPH001542712/12/2024 20:02:25UPH001542712/12/2024 20:02:25
5UPH001542912/15/2024 20:39:16UPH00154291/5/2025 9:36:12
6UPH00154251/5/2025 9:36:12UPH00154251/5/2025 9:36:12
Sheet3
Cell Formulas
RangeFormula
D2:E6D2=LET(n,TEXTSPLIT(TEXTJOIN(CHAR(10),,A2:A4),,CHAR(10)),HSTACK(n,VLOOKUP("*"&n&"*",A2:B4,2,0)))
G2:G6G2=TEXTSPLIT(TEXTJOIN(CHAR(10),,A2:A4),,CHAR(10))
H2:H6H2=LET(c,LEN(A2:A4)-LEN(SUBSTITUTE(A2:A4,CHAR(10),""))+1,TOCOL(IFS(SEQUENCE(,MAX(c))<=c,B2:B4),2))
Dynamic array formulas.
 
Upvote 0
I put this formula into D2 and in E2 I get Invalid cell reference error.
It would be good to see a small set of sample data with XL2BB where you are getting that error.
(If you have trouble with XL2BB, review the "XL2BB Icons greyed out" link in the 'Known XL2BB issues' section near the top of the XL2BB Instructions page linked above.)
 
Upvote 0

Forum statistics

Threads
1,226,837
Messages
6,193,249
Members
453,784
Latest member
Chandni

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