Solved

EXCEL VBA To combine cells into one seperated by

Posted on 2016-08-03
10
40 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:Wass_QA
  • 5
  • 5
10 Comments
 
LVL 43

Expert Comment

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

Author Comment

by:Wass_QA
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
 

Author Comment

by:Wass_QA
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Wass_QA
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:Wass_QA
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:Wass_QA
ID: 41747994
Awesome Saqib.
Thank you very VERY much.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now