So I imported a text file and now I want to search column "A" in a sheet "Info" to see if these phrases ("N o r m a l t e r m i n a t i o n", "E r r o r t e r m i n a t i o n") exist. Here is what I recorded:
PHP Code:
Cells.Find(What:="N o r m a l t e r m i n a t i o n", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Cells.Find(What:="E r r o r t e r m i n a t i o n", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
Range("B4").Select
ActiveCell.FormulaR1C1 = "The analysis resulted in ______"
After finding them, I want excel to display in "B4" in sheet "Info": "This analysis resulted in 'Normal termination'" OR "This analysis resulted in 'Error termination'".
I picture the code being something like:
Find "phrase". If phrase is found, display "str". Else find "other phrase". Display "other phrase".
Sub FindPhrase()
Dim Arr As Variant
Dim i As Long
Dim Rng As Range
Arr = Array("N o r m a l t e r m i n a t i o n", "E r r o r t e r m i n a t i o n")
For i = 0 To UBound(Arr)
With Sheets("Info")
Set Rng = .Columns(1).Find(What:=Arr(i), After:=.Cells(1, "A"), LookIn:= _
xlFormulas, LookAt:=xlPart)
If Not Rng Is Nothing Then
.Range("B4").Value = "This analysis resulted in " & Arr(i)
End If
End With
Next i
End Sub
I want to add "else, if two two phrases aren't found, then display 'this analysis was not complete' ". Just trying to understand what the suggested code is doing (my comments are in ""):
PHP Code:
Dim Arr As Variant "this defines Arr as variable?"
Dim i As Long "this defines i as numbers?"
Dim Rng As Range "this defines Rng as range of values?"
Arr = Array("N o r m a l t e r m i n a t i o n", "E r r o r t e r m i n a t i o n")
For i = 0 To UBound(Arr) "what is UBound(Arr)?"
With Sheets("Info")
Set Rng = .Columns(1).Find(What:=Arr(i), After:=.Cells(1, "A"), LookIn:= _
xlFormulas, LookAt:=xlPart) "what is After:=?"
If Not Rng Is Nothing Then "i am not sure what this means"
.Range("B4").Value = "This analysis resulted in " & Arr(i)
End If
Else "this is what i added to get the 3 case phrase displayed"
.Range("B4").Value = "This analysis was not completed/ interrupted. Please rerun or discard."
Thanks for the prompt reply. I tried to add a 3rd condition to the script and it didn't turn out too well.
So, from what I understand, the for loop tries to find the Arr(0) first. Then if Rng isn't empty, it will put value into cell B4. Then it tries Arr(1). However, now I need a third condition, a case where both "normal termination" and "error termination" aren't found.
Is this what I should add? If so, where should I add this?
PHP Code:
Else
.Range("B4").Value = "This analysis was not completed/ interrupted. Please rerun or discard."
Bookmarks