Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Find Problem

Hi,

Using Code to find a value, and if found, then delete the line.
Simple right?


Cells.Find(what:="2000103", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

If ActiveCell.Value = 2000103 Then
Selection.EntireRow.Delete

End If


But problem is, when the value 2000103 is not present, I get Run Time Error
91.

Any ideas on debugging?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Find Problem

Hi

See the example below that use Set rng and check it with
If Not rng Is Nothing

Sub Find_First()
Dim FindString As String
Dim rng As Range
FindString = InputBox("Enter a Search value")
If Trim(FindString) < "" Then
With Sheets("Sheet1").Range("A:A")
Set rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
Else
MsgBox "Nothing found"
End If
End With
End If
End Sub

You can also use this
http://www.rondebruin.nl/delete.htm#Find


--
Regards Ron de Bruin
http://www.rondebruin.nl



"John" wrote in message ...
Hi,

Using Code to find a value, and if found, then delete the line.
Simple right?


Cells.Find(what:="2000103", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

If ActiveCell.Value = 2000103 Then
Selection.EntireRow.Delete

End If


But problem is, when the value 2000103 is not present, I get Run Time Error
91.

Any ideas on debugging?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Find Problem

Thanks Ron Big Help
Not exactly sure what its doing but hey it works.
Thanks
John

"Ron de Bruin" wrote:

Hi

See the example below that use Set rng and check it with
If Not rng Is Nothing

Sub Find_First()
Dim FindString As String
Dim rng As Range
FindString = InputBox("Enter a Search value")
If Trim(FindString) < "" Then
With Sheets("Sheet1").Range("A:A")
Set rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
Else
MsgBox "Nothing found"
End If
End With
End If
End Sub

You can also use this
http://www.rondebruin.nl/delete.htm#Find


--
Regards Ron de Bruin
http://www.rondebruin.nl



"John" wrote in message ...
Hi,

Using Code to find a value, and if found, then delete the line.
Simple right?


Cells.Find(what:="2000103", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

If ActiveCell.Value = 2000103 Then
Selection.EntireRow.Delete

End If


But problem is, when the value 2000103 is not present, I get Run Time Error
91.

Any ideas on debugging?




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
Problem with 'Find' Dave Excel Discussion (Misc queries) 5 December 15th 09 01:27 PM
Find and Find Next problem Richard Hocking Excel Programming 2 September 13th 06 03:51 PM
Please help me find the problem with this Barb Reinhardt Excel Programming 1 August 29th 06 03:31 PM
Find problem alanthecat Excel Programming 7 July 5th 05 01:17 PM
find problem John Excel Programming 4 July 3rd 04 08:30 AM


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

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

About Us

"It's about Microsoft Excel"