Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Len Len is offline
external usenet poster
 
Posts: 162
Default Error Handle problem

Hi,

I tried to copy some filtered rows. If there is no rows to copy, it
will encounter: Run-time error '1004', No Cells were found. ie the
code stops at "result.SpecialCells(xlCellTypeVisible).Copy"
Then I change the code to "If result Is Nothing Then " and continue,
It smoothly completes the process.
However, it fails to copy when there are rows to copy ie the code
skips copying the rows and reach at End If

Codes Extract

Sheets(1).Select
Dim Lrow As Long
Dim result As Range
Lrow = Range("A" & Rows.Count).End(xlUp).Row
Set result = Range("A2:G" & Lrow + 1)
Range("K1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=11, Criteria1:="0", _
Operator:=xlOr, Criteria2:="<0"
Range("D1").Select
Selection.AutoFilter Field:=4, Criteria1:="=*void*", _
Operator:=xlAnd
If Not result Is Nothing Then
result.SpecialCells(xlCellTypeVisible).Copy
Sheets(2).Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If

Any helps will be much appreciated and thanks in advance

Regards
Len
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Error Handle problem

Hi
I think Nothing refers to a variable with no assigned value (could be
wrong!) so isn't appropriate here.
You could simply ride over the error and ignore it using "on error
resume next" as below. If an error occurs nothing happens, which is
what you want anyway.
Sheets(1).Select
Dim Lrow As Long
Dim result As Range
Lrow = Range("A" & Rows.Count).End(xlUp).Row
Set result = Range("A2:G" & Lrow + 1)
Range("K1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=11, Criteria1:="0", _
Operator:=xlOr, Criteria2:="<0"
Range("D1").Select
Selection.AutoFilter Field:=4, Criteria1:="=*void*", _
Operator:=xlAnd
On error resume next
result.SpecialCells(xlCellTypeVisible).Copy
Sheets(2).Select
Range("A1").Select
ActiveSheet.Paste
On error goto 0
Application.CutCopyMode = False

regards
Paul


On Mar 11, 8:06*am, Len wrote:
Hi,

I tried to copy some filtered rows. If there is no rows to copy, it
will encounter: Run-time error '1004', No Cells were found. ie the
code stops at "result.SpecialCells(xlCellTypeVisible).Copy"
Then I change the code to "If result Is Nothing Then " and continue,
It smoothly completes the process.
However, it fails to copy when there are rows to copy ie the code
skips copying the rows and reach at End If

Codes Extract

* * Sheets(1).Select
* * Dim Lrow As Long
* * Dim result As Range
* * Lrow = Range("A" & Rows.Count).End(xlUp).Row
* * Set result = Range("A2:G" & Lrow + 1)
* * Range("K1").Select
* * Selection.AutoFilter
* * Selection.AutoFilter Field:=11, Criteria1:="0", _
* * * * Operator:=xlOr, Criteria2:="<0"
* * Range("D1").Select
* * Selection.AutoFilter Field:=4, Criteria1:="=*void*", _
* * * * Operator:=xlAnd
* * If Not result Is Nothing Then
* * result.SpecialCells(xlCellTypeVisible).Copy
* * Sheets(2).Select
* * Range("A1").Select
* * ActiveSheet.Paste
* * Application.CutCopyMode = False
* * *End If

Any helps will be much appreciated and thanks in advance

Regards
Len


  #3   Report Post  
Posted to microsoft.public.excel.programming
Len Len is offline
external usenet poster
 
Posts: 162
Default Error Handle problem

Hi Paul,

Thanks for your prompt reply and your suggestion
but I still got the same error
I'm not sure whether the same error is due to the codes which have "On
Error Resume Next with On Error Goto 0 " and also another "On Error
GoTo NextProcess with NextProcess:" used in the earlier parts of codes


Thanks and Regards
Len



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Error Handle problem

Hi
It must be something that is not contained within the error
statements, otherwise you would get no error message (though there may
be an error of course, just no message).
regards
Paul
On Mar 11, 12:41*pm, Len wrote:
Hi Paul,

Thanks for your prompt reply and your suggestion
but I still got the same error
I'm not sure whether the same error is due to the codes which have "On
Error Resume Next with On Error Goto 0 " and also another "On Error
GoTo NextProcess with NextProcess:" used in the earlier parts of codes

Thanks and Regards
Len


  #5   Report Post  
Posted to microsoft.public.excel.programming
Len Len is offline
external usenet poster
 
Posts: 162
Default Error Handle problem

Hi Paul,

Thanks for your advice

After I worked around to debug the codes, there was an error that
there is no cells to copy if no cells were found but it still not able
to skip the line of codes and remains at
"result.SpecialCells(xlCellTypeVisible).Copy"

Then I tried to separate the codes which contains "On Error GoTo
NextProcess " and "On Error Resume Next " into different sub
procedures, it works perfectly.

Does it mean that the codes can not have both "On Error GoTo
NextProcess " and "On Error Resume Next " within the same sub
procedure ?

Regards
Len


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to handle automation error? RB Smissaert Excel Programming 2 February 27th 06 12:56 AM
Best way to handle this problem Sandy Excel Programming 6 October 30th 05 11:34 PM
Error Handle PR[_3_] Excel Programming 3 August 10th 05 10:49 PM
How to handle error 8007000e Memory Error L. A. M. Excel Programming 6 June 28th 05 04:05 AM


All times are GMT +1. The time now is 10:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"