Solved

excel question special need

Posted on 2013-01-08
11
245 Views
Last Modified: 2013-03-08
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
Comment
Question by:Matt Pinkston
  • 7
  • 4
11 Comments
 
LVL 26

Expert Comment

by:redmondb
ID: 38756551
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
 

Author Comment

by:Matt Pinkston
ID: 38756603
not familiar with code, but how do you run?
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38756625
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Matt Pinkston
ID: 38756695
it worked perfect, so how do I implement on my own file?
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38756836
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
 

Author Comment

by:Matt Pinkston
ID: 38756973
will do it a lot
one file
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38757088
pinkstonmp,

Apologies, one last question - which version of Excel?

Thanks,
Brian.
0
 
LVL 26

Accepted Solution

by:
redmondb earned 500 total points
ID: 38757244
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
 
LVL 26

Expert Comment

by:redmondb
ID: 38774304
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
 

Author Comment

by:Matt Pinkston
ID: 38965510
Brian,

is there a way to reverse this?  I opened a new question on this.  So basically going the opposite way.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38967664
Pinkstonmp,

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

Regards,
Brian.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Excel Formula Help 3 35
Getting rid of #VALUE! 7 23
remove extra space at end of cell 12 35
Need conditional formating when doubles 14 21
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question