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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.