How do i get a macro to???

T

traineeross

I am writing a macro which i need to search through a list of data containing
peoples names, and if found return the value in the cell adjacent to it on
the right.

This i can do, however the list of names changes depending on whether or not
they have met all their deadlines, so if they have a good month they will not
appear on the list.

Can i get the macro to do something if it finds the name in the list, and
something else if it doesn't?

How would i write this?

Many thanks for your help

Jody
 
D

Don Guillett

have a look in the vba help index for FINDNEXT. There is an excellent
example.
 
O

Otto Moehrbach

Something like this perhaps. HTH Otto
Sub FindName()
Dim ThingToGet As Variant
Dim RngColA As Range 'Range to search
'Set RngColA = Set the range to search
If RngColA.Find(What:="The name to find", LookAt:=xlWhole) Is Nothing
Then _
'Things to do if name is not found
ThingToGet = RngColA.Find(What:="The name to find",
LookAt:=xlWhole).Offset(, 1).Value
End Sub
 
T

traineeross

Cheers for your reply however I can get the macro to find every thing i want
it to, the problem is when it searches and there is nothing to find as the
name isn't on the list (this is because the staff member has met all
deadlines and isn't on the list) this results in an error message saying it
couldn't be found.

I then need to get the macro to accept the error and proceed to the next
name search.

This needs to be included in every search as they may in any month not
appear on the list .

Many thanks Jody Williams
 
D

Don Guillett

cheers for looking at the example cited
With Worksheets(1).Range("a1:a500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top