Hi All,
I'm writing this macros and could use some help. So far the macro finds a word in the spreadsheet and then adjacent word. For example:
"The building has a broken pipe beneath the first floor."
1.Find Text broken
2.Find text broken and adjacent word pipe
To accomplish this task I parsed the words into separate cells and then find the word broken then do a find next in the adjacent cell using findoffset in my code. I added an error handler if a word is not in the spreadsheet.
What I need help doing next is:
1. Define adjacent as words show up as before/after- meaning, treat "pipe broken" and "broken pipe" the same. I'm guessing that would be the use of some previous or next code?
2. My error handler doesn't exclude NULLS in a paragraph. I would need to handle NULLS in a paragraph so that it doesn't show the count of NULLS.The null situation can happen if/when the word of interest "example broken" is at end of a paragraph or a document .
3. I'm guessing I will need a RegExp to handle ignoring common words such as "a", "an", "if", "and", "or" etc. For example, I do not want to find "broken" and adjacent word "a" , "an", "if", "and", "or" etc.
This is my macro:
Sub Module6()
'
'FindPlusOffset&Count
'
'
Dim ws As Worksheet
Dim match As Range
Dim findMe As String
Dim findOffset As String
Set ws = ThisWorkbook.Sheets("Sheet1")
findMe = "broken"
Set match = ws.Cells.Find(findMe)
If (Not match Is Nothing) Then
findOffset = match.Offset(, 1).Value
Number = Evaluate("=SUMPRODUCT(--(NOT(ISERROR(FIND(""" & findOffset & """,A1:AZ96,1)))))")
MsgBox "The adjacent word to """ & findMe & """ is """ & findOffset & """. The word """ & findOffset & """ is found """ & Number & """ times!"
Else
'not match
MsgBox "Sorry the text was not found please try again. Macro stopping"
End If
End Sub
Thanks for your help in advance!
I'm writing this macros and could use some help. So far the macro finds a word in the spreadsheet and then adjacent word. For example:
"The building has a broken pipe beneath the first floor."
1.Find Text broken
2.Find text broken and adjacent word pipe
To accomplish this task I parsed the words into separate cells and then find the word broken then do a find next in the adjacent cell using findoffset in my code. I added an error handler if a word is not in the spreadsheet.
What I need help doing next is:
1. Define adjacent as words show up as before/after- meaning, treat "pipe broken" and "broken pipe" the same. I'm guessing that would be the use of some previous or next code?
2. My error handler doesn't exclude NULLS in a paragraph. I would need to handle NULLS in a paragraph so that it doesn't show the count of NULLS.The null situation can happen if/when the word of interest "example broken" is at end of a paragraph or a document .
3. I'm guessing I will need a RegExp to handle ignoring common words such as "a", "an", "if", "and", "or" etc. For example, I do not want to find "broken" and adjacent word "a" , "an", "if", "and", "or" etc.
This is my macro:
Sub Module6()
'
'FindPlusOffset&Count
'
'
Dim ws As Worksheet
Dim match As Range
Dim findMe As String
Dim findOffset As String
Set ws = ThisWorkbook.Sheets("Sheet1")
findMe = "broken"
Set match = ws.Cells.Find(findMe)
If (Not match Is Nothing) Then
findOffset = match.Offset(, 1).Value
Number = Evaluate("=SUMPRODUCT(--(NOT(ISERROR(FIND(""" & findOffset & """,A1:AZ96,1)))))")
MsgBox "The adjacent word to """ & findMe & """ is """ & findOffset & """. The word """ & findOffset & """ is found """ & Number & """ times!"
Else
'not match
MsgBox "Sorry the text was not found please try again. Macro stopping"
End If
End Sub
Thanks for your help in advance!