Solved

EXCEL VBA To combine cells into one seperated by

Posted on 2016-08-03
10
57 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
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‚Ķ

688 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