[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


How do I take a single column of data and create multiple columns by keyword?

Posted on 2011-09-14
Medium Priority
Last Modified: 2012-05-12
I have a text file that I import into Excel that shows the revision changes of a part number.  The data is stored as one column and each revision section has a title.  I need to compare the changes between revisions and I would like to see each revision side by side.  Attached is a simple sample of what I am trying to accomplish.  The first sheet shows the original data, the second sheet shows how I want it.
Question by:zepold
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 24

Accepted Solution

StephenJR earned 2000 total points
ID: 36539529
Try this:
Sub x()
Dim rFind As Range, rFind2 As Range, sFind As String, sAddr As String

With Sheets("Original").Columns(1)
    Set rFind = .Find(What:="NEW REVISION", After:=.Cells(.Rows.Count), LookAt:=xlWhole, _
                      MatchCase:=False, SearchFormat:=False)
    If Not rFind Is Nothing Then
        sAddr = rFind.Address
            Set rFind2 = .FindNext(rFind)
            If rFind2.Row < rFind.Row Then
                Range(rFind, .Cells(.Rows.Count)).Copy Sheets("Modified").Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
                Range(rFind, rFind2.Offset(-1)).Copy Sheets("Modified").Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
            End If
            Set rFind = rFind2
         Loop While rFind.Address <> sAddr
    End If
End With
End Sub

Open in new window

LVL 24

Expert Comment

ID: 36539534
That assumes your heading is "NEW REVISION" but just occurred that may not be the case, in which case will need revisiting.
LVL 24

Expert Comment

ID: 36539648
Perhaps if the only distinguishing feature is the case:
Sub x()
Dim r As Range, r1 As Range, r2 As Range, c As Long

Set r = Sheets("Original").Range("A1")

Do Until IsEmpty(r)
    Do Until r.Value = UCase(r.Value)
        Set r = r.Offset(1)
    Set r1 = r
    Set r = r.Offset(1)
    Do Until r.Value = UCase(r.Value)
        Set r = r.Offset(1)
    Set r2 = r.Offset(-1)
    c = c + 1
    Range(r1, r2).Copy Sheets("Modified").Cells(1, c)
    Set r = r2.Offset(1)
End Sub

Open in new window


Author Closing Comment

ID: 36543033
This script worked perfectly.

Thank you very much,


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.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

649 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