Solved

EXCEL VBA To combine cells into one seperated by

Posted on 2016-08-03
10
52 Views
Last Modified: 2016-08-08
Hello,
Can you please help with an Excel  macro.
Column "A",
if the cell is called Tracking ID
Then, I need to combine all cells after the  Tracking ID cell into the first next row cell.
until the cell in Column "C" has a name which starts with QA:
and clear cells.

Please see sample attached sample, before, after.

Thanks,
0
Comment
Question by:W.E.B
[X]
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
  • 5
  • 5
10 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41741201
Sample?
0
 

Author Comment

by:W.E.B
ID: 41741210
Ooooops.
Sample.xlsx
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41744152
Sub qa2qaMerge()
    Dim tid As Range, nxtcel As Range
    Set tid = Cells.Find("Tracking ID", Cells.SpecialCells(xlCellTypeLastCell), , xlWhole).Offset(1)
    Set nxtcel = Range("A1")
    Do While tid.Row > nxtcel.Row
        tid.Value = "TRID: " & tid.Text
        tid.HorizontalAlignment = xlGeneral
        Set nxtcel = Cells.Find("*", tid)
        Do While nxtcel.Row >= tid.Row
            If Left(nxtcel, 3) = "QA:" Then Exit Do
                tid.Value = tid.Text & ", " & nxtcel.Text
                nxtcel.ClearContents
            Set nxtcel = Cells.Find("*", nxtcel)
        Loop
        Set tid = Cells.Find("Tracking ID", nxtcel, , xlWhole).Offset(1)
    Loop
End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:W.E.B
ID: 41744343
Hi Saqib,
Appreciate your help,
I'm trying the code on about 1000 Rows,
it just keeps looping and doesn't stop.

thanks
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41744351
Can you share the file?
0
 

Author Comment

by:W.E.B
ID: 41744378
Please see attached sample
Sample.xlsx
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41744519
This file is very much different from the previous sample.

The infinite loop is because there is no QA: after the last Tracking ID.

Do you want to do it this way?
0
 

Author Comment

by:W.E.B
ID: 41744539
yes, please
thank you very much
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 41747462
Sub qa2qaMerge()
    Dim tid As Range, nxtcel As Range, qacel As Range
    Set tid = Cells.Find("Tracking ID", Cells.SpecialCells(xlCellTypeLastCell), , xlWhole).Offset(1)
    Set nxtcel = Range("A1")
    Set qacel = nxtcel
    Do While tid.Row > nxtcel.Row And tid.Row > qacel.Row
        tid.Select
        tid.Value = "TRID: " & tid.Text
        tid.HorizontalAlignment = xlGeneral
        Set qacel = Range(tid, Cells.SpecialCells(xlCellTypeLastCell)).Find("QA:", tid, , xlPart)
        Set nxtcel = Cells.Find("*", tid)
        nxtcel.Select
        Do
            If nxtcel.Row < tid.Row Then Exit Do
            If Not qacel Is Nothing Then
                If nxtcel.Row >= qacel.Row Then Exit Do
            End If
            If Left(nxtcel, 3) = "QA:" Then Exit Do
                tid.Value = tid.Text & ", " & nxtcel.Text
                nxtcel.ClearContents
            Set nxtcel = Cells.Find("*", nxtcel)
            nxtcel.Select
        Loop
        If qacel Is Nothing Then Exit Do
        Set tid = Cells.Find("Tracking ID", qacel, , xlWhole).Offset(1)
    Loop
End Sub
0
 

Author Closing Comment

by:W.E.B
ID: 41747994
Awesome Saqib.
Thank you very VERY much.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

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.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
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.

749 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