View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
austris austris is offline
external usenet poster
 
Posts: 9
Default Can't fix On Error statement

Stefi,
Great! Now it works! Thanks A LOT!!!
Still, if it's not too much asked... - I'm trying to understand why it
didn't work but now does, so that i could fix similar issues next time
myself.
So, if you could let me know if this would be correct description:
1. this bit "On Error Resume Next" makes the code jump to next
statement in the code, i.e., "If Err.Number = 0"
2. the "Err.Number = 0" basically means that there is no Error, i.e, if
there is an error, then "If Err.Number = 0" returns FALSE and that
trigers the "On Error GoTo 0"
3. the "On Error GoTo 0" in turn stops any Error handler and thus the
code just proceeds to next statement, i.e. "Next v"
and that's it.

It would be immensely appreciated if you coould confirm/comment if the
above is correct - i wouldn't trouble you next time :)

And thanks again!

Stefi wrote:
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?