Code help required

Rohith1324

Board Regular
Joined
Feb 27, 2018
Messages
114
Hi,

I have one spreadsheet with multiple lines ( in thousands )

In total I have 10 columns( headers ) and many rows. Each row will be unique.

In one of the column user have an option to enter multiple values, so they update it like 5555565657/5786543789/5654321678

Sometime they have used the separator "/", "&", ","...

My requirement is for the value after each separator should have one seperate line with same row line details for the 3 lines except this cell value... For example in the above example I have 3 values so by running macro excel should split that into 3 lines.

5555565657
5786543789
5654321678

Regards,
Rohith
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
5th column
Try this:

VBA Code:
Sub a1125791a()
Dim x As String
Application.ScreenUpdating = False
    For Each x In Array("/", "&", ",") 'change to suit
    Range("E:E").Replace What:=x, Replacement:=vbLf, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This should work for whatever they use as delimiters except perhaps commas. Excel sees some numeric strings with commas as a single number without the commas.

Code:
Sub t()
Dim col As Long, c As Range, i As Long, spl As Variant
col = 5
With ActiveSheet
    For Each c In Intersect(.UsedRange, .Cells(2, col).Resize(.UsedRange.Rows.Count - 1))
        For i = 1 To Len(c.Value)
            If Not IsNumeric(Mid(c.Value, i, 1)) Then
                c.Replace Mid(c.Value, i, 1), " "
            End If
        Next
        spl = Split(c, " ")
        c.EntireRow.Copy
        If UBound(spl) > 0 Then
            c.Offset(1).Resize(UBound(spl)).EntireRow.Insert
        End If
        Application.CutCopyMode = False
        c.Resize(UBound(spl) + 1) = Application.Transpose(spl)
     Next
End With
End Sub
 
Upvote 0
This should work for whatever they use as delimiters except perhaps commas. Excel sees some numeric strings with commas as a single number without the commas.

Code:
Sub t()
Dim col As Long, c As Range, i As Long, spl As Variant
col = 5
With ActiveSheet
    For Each c In Intersect(.UsedRange, .Cells(2, col).Resize(.UsedRange.Rows.Count - 1))
        For i = 1 To Len(c.Value)
            If Not IsNumeric(Mid(c.Value, i, 1)) Then
                c.Replace Mid(c.Value, i, 1), " "
            End If
        Next
        spl = Split(c, " ")
        c.EntireRow.Copy
        If UBound(spl) > 0 Then
            c.Offset(1).Resize(UBound(spl)).EntireRow.Insert
        End If
        Application.CutCopyMode = False
        c.Resize(UBound(spl) + 1) = Application.Transpose(spl)
     Next
End With
End Sub
It's working when there are no blank cell in between...if there are any blank cells in between...it is throwing runtime error 13 type mismatch
 
Upvote 0
Hi Akuini, when trying your code...im getting compile error - for each control variable must be variant or object and for each X getting highlighted.
Sorry, my mistake. X should be variant not string.
VBA Code:
Sub a1125791a()
Dim x
Application.ScreenUpdating = False
    For Each x In Array("/", "&", ",") 'change to suit
    Range("E:E").Replace What:=x, Replacement:=vbLf, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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