PC Review


Reply
Thread Tools Rate Thread

Clearing Errors

 
 
jswalsh33
Guest
Posts: n/a
 
      12th Oct 2009

I have tried hard to make this code work but I have not been successful.

Sheets("CustData").Activate
Num = Sheets("CustData").Range("DG5001")
For x = 1 To 4
If x = 1 Then CustN = Sheets("OrderEntry").Range("D7") Else CustN =
Sheets("OrderEntry").Cells((x - 2) * 14 + 23, 4)
Sheets("CustData").Range(Cells(6, 1), Cells(Num + 10, 1)).Select
On Error GoTo Line2
Selection.Find(What:=CustN, After:=ActiveCell, LookIn:=xlValues,
LookAt:= _
xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
Row = ActiveCell.Row
Sheets("CustData").Range(Cells(Row, 1), Cells(Row, 110)).ClearContents
Sheets("CustData").Cells(Row, 112).ClearContents
Line2:
If Err.Number <> 0 Then Err.Clear
Next x

In this example CustN="" for all x's.
The code works fine for the first x. It jumps to Line2 and proceeds to the
next x.

However the "Find" line fails with a runtime error 91 when x =2, 3 or 4.

What am I doing wrong?

Thanks for your help.

Jim Walsh
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      12th Oct 2009
This should help you find the problem

with Sheets("CustData")
Num = .Range("DG5001")
For x = 1 To 4
If x = 1 Then
CustN = Sheets("OrderEntry").Range("D7")
Else
CustN = Sheets("OrderEntry").Cells((x - 2) * 14 + 23, 4)
end if
set cell = .Range(Range("A6"), Range("A" & (Num + 10))
set c = cell.Find(What:=CustN, _
LookIn:=xlValues, _
LookAt:= xlWhole)
if not c is nothing then
Row = c.Row
.Range(.Range("A" & Row), .Range("DF" & Row).ClearContents
.Range("DH" & Row).ClearContents
end if
Next x
end with


"jswalsh33" wrote:

>
> I have tried hard to make this code work but I have not been successful.
>
> Sheets("CustData").Activate
> Num = Sheets("CustData").Range("DG5001")
> For x = 1 To 4
> If x = 1 Then CustN = Sheets("OrderEntry").Range("D7") Else CustN =
> Sheets("OrderEntry").Cells((x - 2) * 14 + 23, 4)
> Sheets("CustData").Range(Cells(6, 1), Cells(Num + 10, 1)).Select
> On Error GoTo Line2
> Selection.Find(What:=CustN, After:=ActiveCell, LookIn:=xlValues,
> LookAt:= _
> xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
> MatchCase:= _
> False).Activate
> Row = ActiveCell.Row
> Sheets("CustData").Range(Cells(Row, 1), Cells(Row, 110)).ClearContents
> Sheets("CustData").Cells(Row, 112).ClearContents
> Line2:
> If Err.Number <> 0 Then Err.Clear
> Next x
>
> In this example CustN="" for all x's.
> The code works fine for the first x. It jumps to Line2 and proceeds to the
> next x.
>
> However the "Find" line fails with a runtime error 91 when x =2, 3 or 4.
>
> What am I doing wrong?
>
> Thanks for your help.
>
> Jim Walsh

 
Reply With Quote
 
jswalsh33
Guest
Posts: n/a
 
      12th Oct 2009
Joel,

Thank you very much. The code worked very well after I removed the dots in
front of the Ranges. They gave me compile errors.

I would appreciate it if you could tell me why the code I wrote did not work.

Jim Walsh

"Joel" wrote:

> This should help you find the problem
>
> with Sheets("CustData")
> Num = .Range("DG5001")
> For x = 1 To 4
> If x = 1 Then
> CustN = Sheets("OrderEntry").Range("D7")
> Else
> CustN = Sheets("OrderEntry").Cells((x - 2) * 14 + 23, 4)
> end if
> set cell = .Range(Range("A6"), Range("A" & (Num + 10))
> set c = cell.Find(What:=CustN, _
> LookIn:=xlValues, _
> LookAt:= xlWhole)
> if not c is nothing then
> Row = c.Row
> .Range(.Range("A" & Row), .Range("DF" & Row).ClearContents
> .Range("DH" & Row).ClearContents
> end if
> Next x
> end with
>
>
> "jswalsh33" wrote:
>
> >
> > I have tried hard to make this code work but I have not been successful.
> >
> > Sheets("CustData").Activate
> > Num = Sheets("CustData").Range("DG5001")
> > For x = 1 To 4
> > If x = 1 Then CustN = Sheets("OrderEntry").Range("D7") Else CustN =
> > Sheets("OrderEntry").Cells((x - 2) * 14 + 23, 4)
> > Sheets("CustData").Range(Cells(6, 1), Cells(Num + 10, 1)).Select
> > On Error GoTo Line2
> > Selection.Find(What:=CustN, After:=ActiveCell, LookIn:=xlValues,
> > LookAt:= _
> > xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
> > MatchCase:= _
> > False).Activate
> > Row = ActiveCell.Row
> > Sheets("CustData").Range(Cells(Row, 1), Cells(Row, 110)).ClearContents
> > Sheets("CustData").Cells(Row, 112).ClearContents
> > Line2:
> > If Err.Number <> 0 Then Err.Clear
> > Next x
> >
> > In this example CustN="" for all x's.
> > The code works fine for the first x. It jumps to Line2 and proceeds to the
> > next x.
> >
> > However the "Find" line fails with a runtime error 91 when x =2, 3 or 4.
> >
> > What am I doing wrong?
> >
> > Thanks for your help.
> >
> > Jim Walsh

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      12th Oct 2009
You should of removed the periods, instead add them to this line

from
set cell = .Range(Range("A6"), Range("A" & (Num + 10))
to
set cell = .Range(.Range("A6"), .Range("A" & (Num + 10))

You want to make sure the correct sheet si being referenced and without the
periods the wrong sheet may be selected.


"jswalsh33" wrote:

> Joel,
>
> Thank you very much. The code worked very well after I removed the dots in
> front of the Ranges. They gave me compile errors.
>
> I would appreciate it if you could tell me why the code I wrote did not work.
>
> Jim Walsh
>
> "Joel" wrote:
>
> > This should help you find the problem
> >
> > with Sheets("CustData")
> > Num = .Range("DG5001")
> > For x = 1 To 4
> > If x = 1 Then
> > CustN = Sheets("OrderEntry").Range("D7")
> > Else
> > CustN = Sheets("OrderEntry").Cells((x - 2) * 14 + 23, 4)
> > end if
> > set cell = .Range(Range("A6"), Range("A" & (Num + 10))
> > set c = cell.Find(What:=CustN, _
> > LookIn:=xlValues, _
> > LookAt:= xlWhole)
> > if not c is nothing then
> > Row = c.Row
> > .Range(.Range("A" & Row), .Range("DF" & Row).ClearContents
> > .Range("DH" & Row).ClearContents
> > end if
> > Next x
> > end with
> >
> >
> > "jswalsh33" wrote:
> >
> > >
> > > I have tried hard to make this code work but I have not been successful.
> > >
> > > Sheets("CustData").Activate
> > > Num = Sheets("CustData").Range("DG5001")
> > > For x = 1 To 4
> > > If x = 1 Then CustN = Sheets("OrderEntry").Range("D7") Else CustN =
> > > Sheets("OrderEntry").Cells((x - 2) * 14 + 23, 4)
> > > Sheets("CustData").Range(Cells(6, 1), Cells(Num + 10, 1)).Select
> > > On Error GoTo Line2
> > > Selection.Find(What:=CustN, After:=ActiveCell, LookIn:=xlValues,
> > > LookAt:= _
> > > xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
> > > MatchCase:= _
> > > False).Activate
> > > Row = ActiveCell.Row
> > > Sheets("CustData").Range(Cells(Row, 1), Cells(Row, 110)).ClearContents
> > > Sheets("CustData").Cells(Row, 112).ClearContents
> > > Line2:
> > > If Err.Number <> 0 Then Err.Clear
> > > Next x
> > >
> > > In this example CustN="" for all x's.
> > > The code works fine for the first x. It jumps to Line2 and proceeds to the
> > > next x.
> > >
> > > However the "Find" line fails with a runtime error 91 when x =2, 3 or 4.
> > >
> > > What am I doing wrong?
> > >
> > > Thanks for your help.
> > >
> > > Jim Walsh

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clearing cells without clearing formulas marsjune68 Microsoft Excel Misc 2 10th Apr 2009 07:39 PM
Seagate drive check utility reports "errors in metadatea file records, other errors critical errors in metadata.." LQQK@mi.sig Storage Devices 0 3rd Feb 2006 04:48 AM
RequiredFieldValidator - Clearing a page with errors =?Utf-8?B?RXl0Y2g=?= Microsoft ASP .NET 2 6th Dec 2005 04:54 AM
Clearing temp files to fix printer errors Michael Bentfeld Microsoft Windows 2000 Printing 1 26th May 2004 05:51 PM
Clearing errors sometimes changes values Jon Skeet [C# MVP] Microsoft Dot NET Compact Framework 2 4th May 2004 03:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:04 PM.