Hello, I am new to VB and I’m trying to use a macro to sort out my Excel text data. Here is an example of my problem.
ColA Col B
P x1
P x2
P x3
B y1
B y2
C z1
C z2
C z3
I am trying to create a macro to delete repetitions in Column A (Col A) but at the same time put data from Column B (x1, x2 and x3) into different columns under the same Row 1. I’m trying to get my data to look like:
Col A Col B Col C Col D
P x1 x2 x3
B y1 y2
C z1 z2 z3
Due to the large amount of data, I am unable to manually do this and would hence like to automate the process. I came up with some code, but there are errors in it. I would really be grateful if I could get some help on this.
Sub LoopRange()
x = ActiveCell.Row
y = x + 1
Do While Cells(x, 1).Value <> ""
Do While Cells(y, 1).Value <> ""
If (Cells(x, 1).Value = Cells(y, 1).Value) Then Range("B1").Offset(0, 1).Select And Cells(y, 1).EntireRow.Delete
Else
y = y + 1
End If
Loop
x = x + 1
y = y + 1
Loop
End Sub
There is a good chance that this code is nothing but lines of garbage. I really hope someone can help me structure it to meet the requirements of the format mentioned above.
Thank you.
Bookmarks