Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

excel question special need

I have an excel spreadsheet with about 6 columns and 350 rows

one of the columns "C" has values separated by a ; within it

now we are told that we cannot user the multi entries separated by a ; so each one needs its own line.

and example of "C" would be A;B;C;D which now need to be three separate lines

before

joe     Blow    A;B;C;D    golf

now

joe     Blow    A    golf
joe     Blow    B    golf
joe     Blow    C    golf
joe     Blow    D    golf


is there a way for me to automatically do this?
0
Matt Pinkston
Asked:
Matt Pinkston
  • 7
  • 4
1 Solution
 
redmondbCommented:
Hi, pinkstonmp.

Please see attached. The code is...
Option Explicit

Sub Split_Semi_Colon()
Dim i As Long
Dim j As Long
Dim xLast_Row As Long
Dim xCell As Range
Dim xArray  As Variant
        
ThisWorkbook.Sheets("Sheet1").Activate

Application.ScreenUpdating = False
    
    xLast_Row = [A1].SpecialCells(xlLastCell).Row
    If xLast_Row < 2 Then
        MsgBox ("No data found - run cancelled.")
        Exit Sub
    End If
    
    For i = xLast_Row To 2 Step -1
        xArray = Split(Cells(i, 3), ";")
        If UBound(xArray) > -1 Then
            For j = UBound(xArray) To 0 Step -1
                If j = 0 Then
                    Cells(i, 3) = xArray(j)
                Else
                    Rows(i).Copy
                    Rows(i + 1).Insert Shift:=xlDown
                    Cells(i + 1, 3) = xArray(j)
                End If
            Next
        End If
    Next

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

Open in new window

Regards,
Brian.
Split-Semi-Colon.xlsm
0
 
Matt PinkstonAuthor Commented:
not familiar with code, but how do you run?
0
 
redmondbCommented:
pinkstonmp,

Press the blue button! Once everything is OK, I'll talk you through how you do it on your own file.

Regards,
Brian.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Matt PinkstonAuthor Commented:
it worked perfect, so how do I implement on my own file?
0
 
redmondbCommented:
pinkstonmp,

A few questions, please...
(1) Is this a one-off or will you be doing it repeatedly?
(2) Do you need to run this against one file or many?

Thanks,
Brian
0
 
Matt PinkstonAuthor Commented:
will do it a lot
one file
0
 
redmondbCommented:
pinkstonmp,

Apologies, one last question - which version of Excel?

Thanks,
Brian.
0
 
redmondbCommented:
pinkstonmp,

These notes are for 2010.

(1) The Developer tab needs to be displayed on your Ribbon's menu bar. If it's not then please do the following (per Excel's Help)...
 - Click the File tab, click Options, and then click the Customize Ribbon category.
 - In the Main Tabs list, select the Developer check box, and then click OK.
(2) Click on "Developer" to display its tab. Click on "Visual Basic". This opens a whole new window - the Visual Basic editor (VBE). Your exact layout may be different, but you'll see something like this...(3) On the VBE's menu bar, click on "Insert" and then "Module". You'll now see something like the following....(4) You may or may not have the "Option Explicit" text. If it's there then delete it - it's already in my code above.
(5) Copy my code from above and paste it into the module (i.e. where the "Option Explicit" is shown in my diagram).
(6) The macro explicitly looks for a sheet called "Sheet1". If your sheet has a different name then change line 10 accordingly.
(7) Close the VBE window.
(8) If your file was already an xlsm, xlsb or xls then simply save it, otherwise do a "Save As" and select the "Excel Macro-Enabled Workbook" type.

When you want to run the macro...
(A) Click on "Developer" to display its tab. Click on "Macros". This displays a dialogue such as the following....(B) Select the macro (if its not already selected) and click on "Run".

Regards,
Brian.
0
 
redmondbCommented:
Thanks, pinkstonmp.

I keep an eye on "my" closed questions for a few weeks, so if you've issues with any of this, please feel free to post here.

Regards,
Brian.
0
 
Matt PinkstonAuthor Commented:
Brian,

is there a way to reverse this?  I opened a new question on this.  So basically going the opposite way.
0
 
redmondbCommented:
Pinkstonmp,

Sorry, I was too slow, but als315 seems to have you well sorted!

Regards,
Brian.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now