Please help me making an excel coding --- Must use Len and Mid function.!! Write
ID: 662879 • Letter: P
Question
Please help me making an excel coding --- Must use Len and Mid function.!!
Write a VBA program to count the number of occurrences of an integer or letter within a larger string (Hint: use a loop along with the LEN and MID functions.) Use one input box to enter a string of arbitrary length, and another input box to enter the value to search for. Then, use a Message Box to display the number of times the search value occurs within the longer string. For example, if the long string is
abccccdghcmkncf
and the search value is c, the answer will be 6.
Explanation / Answer
Dim l_str As String Dim r_str As String Dim s_len As Long Dim len As Long Dim f_ind As Long Dim count As Long l_str = InputBox(Prompt:="Enter a string of arbitrary length", Title:="ENTER YOUR NAME", Default:="Your Name here) r_str = InputBox(Prompt:="Enter a string to be search", Title:="ENTER YOUR NAME", Default:="Your Name here) s_len = len(l_str) len = len(r_str) For i = 1 To s_len f_ind = Mid(l_str,i,len) If exact(f_ind, r_len) = true Then count = count + 1 End If next i return count
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.