Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want the following problem in VBA or VBE(Visual Basic Editor) in Excel Write a

ID: 3676779 • Letter: I

Question

I want the following problem in VBA or VBE(Visual Basic Editor) in Excel

Write a function subroutine called NameExists of type Boolean that takes two arguments of type Range and String, respectively. It searches all of the cells in the given range and checks whether any of them have their Value property equal to the given string. For example, if the string is “Davis”, it checks whether “Davis” is in any of the cells. (A cell containing “Sam Davis” wouldn’t count. The contents have to be “Davis” exactly.) If so, it returns True. Otherwise, it returns False.

Explanation / Answer

Private Function Method2() As Boolean

Dim rng1 As Range
Dim strSearch As String
strSearch = "Davis"
Set rng1 = Range("A:A").Find(strSearch, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
MsgBox "Match found"
Method2 = True
  
Else
MsgBox strSearch & " not found"
Method2 = False
  
End If
End Function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote