Searching online, I just found a code that helped me accomplish what I needed. This is the code:
Sub Test()
Dim Sh As Worksheet
Dim Col As Long
Dim RowFrom As Long
Dim RowTo As Long
Set Sh = Worksheets("Sheet1")
Col = Sh.Cells(1, Sh.Columns.Count).End(xlToLeft).Column + 1
RowFrom = 1
RowTo = 1
With Sh
Do
If IsEmpty(.Cells(RowFrom, 1)) Then Exit Sub
If .Cells(RowFrom, 1).Value = "EN" Then
With .Range(.Cells(RowFrom, 1), .Cells(RowFrom, Col - 1))
.Copy Sh.Cells(RowTo, Col)
.Delete Shift:=xlUp
RowTo = RowTo + 1
End With
Else
RowFrom = RowFrom + 1
End If
Loop
End With
End Sub
Now I'm trying to understand better the dynamic of what the code did, because I need to generalize it.
So for example If after the first 'shift', I needed to do another shift (this time looking for "RA"), that is:
Now,
From:
HS | 14 | 15 | 16 | EN | 18 | 15 | 20 |
HS | 13 | 12 | 11 | EN | 23 | 34 | 21 |
RA | 21 | 32 | 21 |
RA | 12 | 23 | 45 |
CS | 15 | 18 | 32 |
CS | 21 | 14 | 16 |
To:
HS | 14 | 15 | 16 | EN | 18 | 15 | 20 | RA | 21 | 32 | 21 |
HS | 13 | 12 | 11 | EN | 23 | 34 | 21 | RA | 12 | 23 | 45 |
CS | 15 | 18 | 32 |
CS | 21 | 14 | 16 |
What would I have to add to the code?
If someone could help me, I'd appreciate it.
Regards,
Victor
Bookmarks