+ Reply to Thread
Results 1 to 3 of 3

"Factor out" semicolon separated data

Hybrid View

  1. #1
    Registered User
    Join Date
    08-25-2011
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2003
    Posts
    11

    "Factor out" semicolon separated data

    I hope someone can help me figure out a more automated way to accomplish the following:

    It's best illustrated by just looking at the attached Start and Finish screenshots or looking at the attached excel doc, Sheet 1 is the start data, Sheet 2 is the finished data.

    I'll try to describe it in words here:
    1. duplicate rows based on the number of semicolon-separated numbers in the "Model Year" column.
    2. delete the duplicated data within each Model Year cell so that there is one of each year. (e.g. "2006;2007;2008;2009;2010" becomes "2006", next cell down is "2007", next cell down is "2008", etc.)

    I hope I stated that clearly. Thanks very much in advance for any help and/or ideas with this.
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Help Request: "Factor out" semicolon separated data

    Public Sub Test()
    Dim vecYears As Variant
    Dim NumYears As Long
    Dim Lastrow As Long
    Dim i As Long
    
        With ActiveSheet
        
            Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
            For i = Lastrow To 2 Step -1
            
                vecYears = Split(.Cells(i, "C").Value, ";")
                NumYears = UBound(vecYears) - LBound(vecYears) + 1
                .Rows(i + 1).Resize(NumYears - 1).Insert
                .Cells(i, "A").Resize(, 2).AutoFill .Cells(i, "A").Resize(NumYears, 2)
                .Cells(i, "C").Resize(NumYears) = Application.Transpose(vecYears)
            Next i
        End With
    End Sub

  3. #3
    Registered User
    Join Date
    08-25-2011
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Help Request: "Factor out" semicolon separated data

    Thank you, Bob!

    This almost works. One small, unwanted side effect is that the ID numbers and Name numbers are changed. I highlighted changed numbers in yellow in the attached image.

    I'm trying to figure out how to correct that myself, but I have no experience with Visual Basic. Can you perhaps point me in the right direction? I think it has something to do with this line:
    .Cells(i, "A").Resize(, 2).AutoFill .Cells(i, "A").Resize(NumYears, 2)
    Attached Images Attached Images

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1