I am searching in a Loop through multiple lines of data and looking for
conditions. There are at least 3 possible conditions for my fist pass
through.
1. Search finds "defeated"
2. Search finds "you"
3. Search finds neither of the above
I have the following variables:
Parse_Text = CStr(Range("A1").Value)
Find_Text = "you"
I am performing the following task:
AttackNoun = Application.WorksheetFunction.Search(Find_Text, Parse_Text)
The issue occurs when it doesn't find "defeated", it errors out to debug mode.
--------------------------------------
Entire code snippet thus far
Sub Test_Parse()
'
' Test_Parse Macro
' Start of a test Macro to Parse data with rules
'
' Keyboard Shortcut: Ctrl+Shift+G
'
' Select the proper Sheet and Cell A1
Sheets("play1").Select
Range("A1").Select
' First part of routine goes through and counts the number of rows of data
that have data in them
' For now I am just putting the number of the counter in B1 (for debugging
purposes). That number will be used in the next section of code
Counter = 1
StrCounter = CStr(Counter)
Parse_Text = CStr(Range("A1").Value)
Do While Parse_Text ""
Range("A" + StrCounter).Select
Parse_Text = CStr(Range("A" + StrCounter).Value)
Counter = Counter + 1
StrCounter = CStr(Counter)
Loop
Range("B1").Select
Range("B1").Value = (Counter - 1)
' Here I am just setting a variable to equal the number of rows to parse
Num_Rows = Counter - 2
StrNum_Rows = CStr(Num_Rows)
' Now we need to start a Loop to look through the rows, one at a time, for
Num_Rows number of Rows
Counter = 2 'Reset the counter to 1 so we can tell when we are at the
final row
StrCounter = CStr(Counter)
Parse_Text = CStr(Range("A1").Value)
Do While Counter < Num_Rows - 1
Range("A" + StrCounter).Select 'select the first/next row of data to
parse
Parse_Text = CStr(Range("A" + StrCounter).Value)
'MsgBox Parse_Text
'MsgBox Find_Text
'First order of understanding -- Is this a "Deafeated" Line
'If so, then skip line
Find_Text = "defeated"
AttackNoun = Application.WorksheetFunction.Search(Find_Text,
Parse_Text)
If AttackNoun > 1 Then
'Do something
Else
'Second order of understanding -- Are you doing something or is
someone doing something to you?
Find_Text = "You"
AttackNoun = Application.WorksheetFunction.Search(Find_Text,
Parse_Text)
If AttackNoun = 1 Then
Result_Text = CStr("You do something to something")
Range("C" + StrCounter).Select
Range("C" + StrCounter) = Result_Text
End If
If AttackNoun 1 Then
Result_Text = CStr("Something does something to you")
Range("C" + StrCounter).Select
Range("C" + StrCounter) = Result_Text
End If
Counter = Counter + 1
StrCounter = CStr(Counter)
End If
Loop
End Sub
Archived from group: microsoft>public>vb>syntax