I have a list of customer IDs (column B) and purchased products (column C). If the customer has bought more than one product, the cells beneath the customer ID are blank whilst col B lists on each row one product, until it runs out of purchased products for that customer. I want all of the products a customer has purchased in one row though, alongside their ID. (Column A is just a simple helper column, with a non-empty cell for each row of the table).
Code is not my natural area of expertise, but I wrote the below very simple macro to move all the products onto single rows, and delete the empty rows afterwards. However it's slow - it takes about a minute per 1,000 rows, and I have several hundred thousand rows to go through.
Is there any way to make it more efficient?
Sub RearrangeforR()
Range("B1").Select
Do While IsEmpty(Cells(ActiveCell.Row, 1)) = False
If IsEmpty(ActiveCell) = True Then
ActiveCell.Offset(0, 1).Select
Selection.Copy
ActiveCell.Offset(-1, 0).Select
Do While IsEmpty(ActiveCell) = False
ActiveCell.Offset(0, 1).Select
Loop
ActiveCell.PasteSpecial
ActiveCell.Offset(1, 0).Select
ActiveCell.EntireRow.Delete
Cells(ActiveCell.Row, "B").Select
Else: ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub