Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selection.Find errors out when not found

Status
Not open for further replies.

Malc8179

MIS
Oct 8, 2007
28
GB
Hi Guys

i have a bit of code that loops through a number of rows then looks for the information and changes a bit of data

when the selection is not found it errors out with error 91
i have added an error trap but it dont work any ideas

Public Sub AddMissingAlpha()
Dim strvalue As String
Dim strAlpha As Double
Dim strRowNo As Integer
Sheets("Missing_Alpha").Select
Range("A1").Select
On Error GoTo 50

Do Until ActiveCell.Offset(1, 0).Value = ""
DoEvents

ActiveCell.Offset(1, 0).Select
strvalue = ActiveCell.Value
strAlpha = ActiveCell.Offset(0, 1).Value
Sheets("Data").Select
Columns("A:A").Select

If Selection.Find(what:=strvalue).Activate = True Then

strRowNo = ActiveCell.Row
If Range("U" & strRowNo).Value = "" Then
Range("U" & strRowNo).Value = strAlpha
End If


End If
50
Sheets("Missing_Alpha").Select

Loop
End Sub
 
Replace this:
If Selection.Find(what:=strvalue).Activate = True Then

with something like this:
Set c = Selection.Find(what:=strvalue)
If Not c Is Nothing Then
c.Activate

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV

This did the trick, thanks for your help

Malc
 
This did the trick
I know that as I only pressed the F1 key ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top