Can't fix On Error statement
Now it's tested! (I forgot to delete On Error GoTo 0 at the wrong place.)
Sub Rearange_report()
lastrow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
firstrow = Range("A1").End(xlDown).Row
lastcolumn = Range("A1").End(xlToRight).Column
For v = 1 To lastcolumn Step 1
Rows(firstrow).Select 'select first data (entire) row
Cells(firstrow, 256).Activate
On Error Resume Next
Selection.Find(What:=Cells(1, v).Value, After:=ActiveCell,
LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Select
If Err.Number = 0 Then
Range(Cells(firstrow, Selection.Column), Cells(lastrow,
Selection.Column)).Select
Selection.Cut
Cells(2, v).Select
ActiveSheet.Paste
End If
On Error GoTo 0
Next v
End Sub
Regards,
Stefi
€˛austris€¯ ezt Ć*rta:
Thanks, Stefi
The Error doesn't fire anymore but it still doesn't pick the next value
- it proceeds with copying values from first column, i.e., in the
example it copies C11 under A while it should copy under C...
Any ideas?
|