Corrections to pervious post, separate into Columns

Status
Not open for further replies.

SeanLCA

New Member
Joined
Nov 3, 2018
Messages
15
Office Version
  1. 365
Platform
  1. Windows
What is the formula that would separate the (Numbers) into different columns.

Sport 1Sport 2Sport 3Sport 4Sport 5Sport 6Sport 7
Baseball (805) > Basketball (705) > Football (605) > Soccer (505)> Hockey (405)> Pickleball (305)> Golf (205)



The desire result in each column without including >:

Sport 1Sport 2Sport 3Sport 4Sport 5Sport 6Sport 7
Baseball (805) > Basketball (705) > Football (605) > Soccer (505)> Hockey (405)> Pickleball (305)> Golf (205)(805)(705)(605)(505)(405)(305)(205)
 

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.
Not a Formula.
Assumed that your data to be separated is in Cell A2 and the "Sport" Cells are in the Columns to the right of it (B and on).
Code:
Sub Maybe_So()
Dim a, i As Long
a = Split(Cells(2, 1), ">")
    For i = 0 To Len(Cells(2, 1)) - Len(Replace(Cells(2, 1), ">", ""))
        Cells(2, 1).Offset(, i + 1).Value = Mid(Trim(a(i)), InStr(Trim(a(i)), "(") + 1, InStrRev(Trim(a(i)), ")") - InStr(Trim(a(i)), "(") - 1) * -1
    Next i
End Sub
If you're stuck on using a Formula, someone will come buy to visit this post and give you one.
 
Upvote 0
When testing, the values between the opening and closing parenthesis became negative values. I thought that that was needed as the result.
So don't use the code in Post #2.
This should be the one to use, if you want to use a macro that is.
Code:
Sub Maybe_So()
Dim a, i As Long
a = Split(Cells(11, 1), ">")
    For i = 0 To Len(Cells(11, 1)) - Len(Replace(Cells(11, 1), ">", ""))
        Cells(11, 1).Offset(, i + 1).Value = "'" & Mid(Trim(a(i)), InStr(Trim(a(i)), "("), InStr(Trim(a(i)), ")") + 1 - InStr(Trim(a(i)), "("))
    Next i
End Sub
 
Upvote 0
2 More possibilities. Both using nested Trim functions.
You can extend your data string (Cell A2) as much as desired.
The second macro (Maybe_So_4) formats the cell to text to avoid the result becoming a negative number because of a number between brackets.
Code:
Sub Maybe_So_3()
Dim i As Long
    For i = 0 To Len(Cells(2, 1)) - Len(Replace(Cells(2, 1), ">", ""))
        Cells(2, 1).Offset(, i + 1).Value = "'" & Trim(Split(Trim(Split(Cells(2, 1), ">")(i)), " ")(1))
    Next i
End Sub
Code:
Sub Maybe_So_4()
Dim i As Long
    For i = 0 To Len(Cells(2, 1)) - Len(Replace(Cells(2, 1), ">", ""))
        With Cells(2, 1).Offset(, i + 1)
            .NumberFormat = "@"
            .Value = Trim(Split(Trim(Split(Cells(2, 1), ">")(i)), " ")(1))
        End With
    Next i
End Sub

Note: In Post #3, the cell references ought to be changed to "Cells(2, 1)"
Leftover from testing at that cell reference.
 
Upvote 0
Duplicate to: Separate in to different columns

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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