I want a macro to loop over column B and copy the cells range from cell A of the first row to cell B of the last row for references that have the same first four numbers. I have references in column B.
i.e
Column A |
Column B |
13/01/23 |
0501765 |
14/01/23 |
0501766 |
13/01/23 |
0502023 |
15/01/23 |
0512301 |
In this case, the code would first copy the range A1:B2, which I would then instruct it to paste (I know how to do this), after which it would repeat the loop and copy the range A3:B3, and so on.
Can someone help? I just want to know what the syntax would be for something like this.
I don’t know much about loops, here’s what I’ve come up with so far.
Dim WorkRng as Range
Set WorkRng = Range(“B:B”)
For i = 1 To WorkRng.Rows.Count
If Left(WorkRng.Cells(i, 2).Value, 4) <> Left(WorkRng.Cells(i + 1, 2).Value, 4)