VBA to split cells

I need help with splitting cell based on delimiter. please see attached file.

i have uploaded a file that shows Before and After.

i need to help with VBA to convert before sheet and create sheet like "AFTER" worksheet.

any help is appreciated.
EE.xlsx
LVL 2
Skylar-BarlowAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Try this.
Sub SplitStuff()
Dim arrIn As Variant
Dim arrOut()
Dim I As Long

    With Sheets("BEFORE")
        arrIn = .Range("A7", .Cells(7, Columns.Count).End(xlToLeft)).Value
    
        ReDim arrOut(1 To 2, 1 To UBound(arrIn, 2))
        
        For I = 1 To UBound(arrIn, 2)
            If InStr(arrIn(1, I), "/") > 0 Then
                arrOut(1, I) = Split(arrIn(1, I), "/")(1)
                
                arrOut(2, I) = Split(arrIn(1, I), "/")(0)
            Else
                arrOut(2, I) = arrIn(1, I)
            End If
        Next I
        
        .Range("A6").Resize(2, UBound(arrOut, 2)).Value = arrOut
        
        .Rows(1).Resize(5).Delete
        
    End With
    
End Sub

Open in new window

0
Skylar-BarlowAuthor Commented:
thanks Norie.  it brings the change into my existings sheet.  how can i modify this, so that it create the new worksheet "After" and pastes the data there?
0
MurpheyApplication ConsultantCommented:
Is the heading the only difference???
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Skylar-BarlowAuthor Commented:
yes. only headings to be split as it is shown in the worksheet "AFTER"

simply put, i have the data as shown in worksheet "Before" and i need it to be added as new sheet like shown in the sheet "AFTER"
0
NorieAnalyst Assistant Commented:
Is the 'AFTER' sheet an existing sheet or do you want to add a new sheet, call it 'AFTER', transfer the data from 'BEFORE' to it and then do the split?
0
Skylar-BarlowAuthor Commented:
in real work, i do not have "AFTER" worksheet. i have manually created it in this example, to show what i am looking for as result.

so, i only have the workbook called "BEFORE", so i need to run the macro, so that it creates the worksheet "AFTER"
0
MurpheyApplication ConsultantCommented:
You can use the standard substring function from excel to take the right part of the string,

I prefer VB-Functions over VB-Subroutines,

=GetPart(sourceCell;"/";1) gives the first label part
=GetPart(sourceCell;"/";2) gives the second label part
=GetPart(sourceCell;"/";3) would gives the third if ist exist

(You can replace the "/" by any other value (if required)



Function GetPart(dta As String, sep As String, part As Integer)

Dim DtaPart() As String

DtaPart = Split(dta, sep)
part = part - 1

GetaArt = DtaPart(part)

End Function

Open in new window

0
NorieAnalyst Assistant Commented:
Give this a try.
Sub SplitStuff()
Dim arrIn As Variant
Dim arrOut()
Dim I As Long

    Sheets("BEFORE").Copy After:=Sheets("BEFORE")
    
    ActiveSheet.Name = "AFTER"
    
    With Sheets("AFTER")
    
        arrIn = .Range("A7", .Cells(7, Columns.Count).End(xlToLeft)).Value
    
        ReDim arrOut(1 To 2, 1 To UBound(arrIn, 2))
        
        For I = 1 To UBound(arrIn, 2)
            If InStr(arrIn(1, I), "/") > 0 Then
                arrOut(1, I) = Split(arrIn(1, I), "/")(1)
                
                arrOut(2, I) = Split(arrIn(1, I), "/")(0)
            Else
                arrOut(2, I) = arrIn(1, I)
            End If
        Next I
        
        .Range("A6").Resize(2, UBound(arrOut, 2)).Value = arrOut
        
        .Rows(1).Resize(5).Delete
        
    End With
    
End Sub

Open in new window

2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Skylar-BarlowAuthor Commented:
Norie,

Thank you so very much!

this is exactly what i was imagining.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.