Hi all
I would like to search a Excel List of names(voters Registration list) by typing a name to see if that person is registered. Can anyone advice me how to do it or provide me with a sample program
Many thanks

Recommended Answers

Try the following, in your macro -

Function TextExtract(ByVal strSearchFor, ByVal Target As Variant) As String
Dim OneCell As Range

   TextExtract = ""
   If TypeName(Target) = "Range" Then
     For Each OneCell In Target
       If InStr(1, OneCell.Text, strSearchFor, vbTextCompare) > 0 Then
         TextExtract = strSearchFor
         Exit For
       End …
Jump to Post

All 2 Replies

Try the following, in your macro -

Function TextExtract(ByVal strSearchFor, ByVal Target As Variant) As String
Dim OneCell As Range

   TextExtract = ""
   If TypeName(Target) = "Range" Then
     For Each OneCell In Target
       If InStr(1, OneCell.Text, strSearchFor, vbTextCompare) > 0 Then
         TextExtract = strSearchFor
         Exit For
       End If
     Next OneCell
   ElseIf TypeName(Target) = "String" Then
     If InStr(1, Target, strSearchFor, vbTextCompare) > 0 Then TextExtract = strSearchFor
   End If

End Function

Example Usage (As a worksheet function):

=TextExtract("3b",A40:A46)
''3b will be the text searched for...

It does not return which cell in the range contains the text. In the case shown only cell A43 contained "3B". This function will search the text sequentially until the condition is true then it will stop searching. Text search will work the same way.

Note that this function is not case sensitive. It will not return how many times the text is present. A modification can be made to have the function count how many cases of the text appear.

Please read more from this link with some more sample code...

hi Industrious poster
Thanks for the response. I will try it later and get back

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.