• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Split function invba

Hello,
another question,
I have this in colum A
Name1 and Name2, Name3, Name4 (16)
I am looking for a piece of code that leaves
Name1 and Name2, Name3, Name4 in colom A
But puts ,split and puts (16) in colom B
 
Something like this. Change sheet and/or cells as needed.
Code:
Sub Test()
Dim x As Variant
With Sheet1
x = Split(.Cells(1, 1).Value, Chr(32), , vbTextCompare)
x = x(UBound(x))
.Cells(1, 1).Value = Trim(Replace(.Cells(1, 1).Value, x, ""))
.Cells(1, 2).NumberFormat = "@"
.Cells(1, 2).Value = Trim(x)
End With
End Sub
 
That's why it's good idea to post question with sample data. ;)

The code won't work as you have blank for cells(1, 1) (i.e. A1).

Use this one.
Code:
Sub Test()
Dim x As Variant
Dim lRow As Long
Dim cel As Range

With Sheets("Blad1")
    lRow = .Cells(Rows.Count, 1).End(xlUp).Row
    For Each cel In .Range("A3:A" & lRow)
        x = Split(cel.Value, Chr(32), , vbTextCompare)
        x = x(UBound(x))
        cel.Value = Trim(Replace(cel.Value, x, ""))
        cel.Offset(0, 1).NumberFormat = "@"
        cel.Offset(0, 1).Value = Trim(x)
    Next cel
End With
End Sub
 
Hi !​

dotchieJack, as you can start yourself just using Macro Recorder :
Code:
Sub Macro1()
'
' Macro1 Macro
' Macro enregistrée le 27/05/2016 par The Noob Simulator
'
     Range("A3:A4").Select
    Selection.Replace What:=")", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
    Selection.TextToColumns Destination:=Range("A3"), DataType:=xlDelimited, _
        TextQualifier:=xlNone, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar:="("
    Range("A1").Select
End Sub
 
Name1 and Name2, Name3, Name4 (16)
I am looking for a piece of code that leaves
Name1 and Name2, Name3, Name4 in colom A
But puts ,split and puts (16) in colom B
Code:
Sub test()
    Dim r As Range
    For Each r In Range("a3", Range("a" & Rows.Count).End(xlUp))
        If r.Value Like "*(*" Then r.Resize(, 2) = Application.Trim(Split(Replace(r, "(", Chr(2) & "'("), Chr(2)))
    Next
End Sub
 
Back
Top