Wondering why this piece of code does not work properly.
Sub copyfirst()
For i = 1 To Sheet20.Cells(Rows.Count, 1).End(xlUp).Row
Set x = Sheet20.Range("A" & i)
'here i tell vba to find text in bold and in black
If x.Characters(i, 1).Font.Color = RGB(0, 0, 0) And x.Characters(1, 1).Font.Bold = True Then
res = x.Text
'then i copy it in another sheet in column 1
x.Copy Sheet21.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Debug.Print x.Address
x.Offset(1, 2).Activate
'PROBLEM! here is the problem
Debug.Print x.Offset(1, 2).Address
Range(ActiveCell, ActiveCell.End(xlDown)).Copy
Sheet21.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=True
Else: GoTo Nextiteration
End If
Nextiteration:
Next i
End Sub
So the problem is in the line x.Offset(1, 2).Activate. In fact, x is in A & i, so the offset(1,2) should give me C & i+1.
Instead, it gives me column D! Why is that?
Here the debug.print address of x and x.0ffset(1,2)
x.address= $A$3
x.offset(1,2)= $D$4
It should be C4! Not D4! It always gives me D4 except for the last variable it finds, where it correctly gives me column C.
Why is that?