Thursday, February 16, 2012


=FIND("Profit", A21)
=LEN("Profit")
=REPLACE(A21, B22, B23, "Loss")


Sub ReplaceProfitWithLoss()
    Dim Sentence As String
    Dim Result As String
    Sentence = "Quarterly Profit, 2012"
   
    Dim pos As Integer
    pos = InStr(1, Sentence, "Profit")
   
    Dim length As Integer
    length = Len("Profit")
   
    Result = Application.WorksheetFunction.Replace(Sentence, pos, length, "Loss")
    Debug.Print Result
End Sub

Function ReplaceProfitWithLoss(Sentence As String) As String
    Dim Result As String
    Sentence = "Quarterly Profit, 2012"
   
    Dim pos As Integer
    pos = InStr(1, Sentence, "Profit")
   
    Dim length As Integer
    length = Len("Profit")
   
    Result = Application.WorksheetFunction.Replace(Sentence, pos, length, "Loss")
    ReplaceProfitWithLoss = Result
End Function

HW:
Write:
CountNumberOfOccurrences("Big Bob's Burgers", "B")

CountNumberOfOccurrencesOfString("Big Bob's Burgers", "Bi")

No comments:

Post a Comment