Hi, i have a spreadsheet with 100's of rows of data.
I have found a piece of code that removes text from a cell after the symbol ">" which is as follows:
What i require is a slight modification so that it removes all text in the cell onwards from the word "is" - eg.Sub test() Dim x As String With ActiveSheet.UsedRange x = .Address .Value = Evaluate("if(" & x & "<>"""",if(isnumber(find("">""," & x _ & ")),left(" & x & ",find("">""," & x & ")-1)," & x & "),"""")") End With End Sub
This is what the cell contains:
Windows Service SurfControl Web Filter Version 5.5 Service Pack 2 Service is Up
I require the following to be displayed:
Windows Service SurfControl Web Filter Version 5.5 Service Pack 2 Service
The reason i want the deletion from the word "is" because there are many different phrases that the cell contains after the word 'is' - e.g. is Up, is Down, is Critical etc etc..
Of course a find and replace option isnt suitable due to the volume of data. A piece of code is ideal so that it can be linked to a macro.
Any advice?
Last edited by nervous_pilchard; 01-21-2011 at 10:28 AM. Reason: solved!
I don't see why? Selecting the data then Ctrl+HOf course a find and replace option isnt suitable due to the volume of data.
Find what: is*
Replace with: (leave blank)
Replace all
Does it take that long?
Quoting entire posts clutters the forum and makes threads hard to read !
If you are pleased with a member's answer then use the Star icon to rate it
Click here to see forum rules
Perhaps it is not an issue but
Find what: is * ("is" space "*")
Might be safer
Purely for sake of Evaluate demo. you could modify to:
again this assumes to always look for <space>is<space> to preclude false positives.Value = Evaluate("IF(ISTEXT(" & x & "),LEFT(" & x & ",FIND("" is "","" ""&" & x & "&"" is "")-2),REPT(" & x & ",1))")
(we add " is " at the end of each string to avoid need for error handling)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Marcol, as far as I know, the space doesn't matter, as the wildcard takes care of it
Quoting entire posts clutters the forum and makes threads hard to read !
If you are pleased with a member's answer then use the Star icon to rate it
Click here to see forum rules
@ arthurbr
The point I was making might be illustrated by this string.
"Windows Issue 2 SurfControl Web Filter Version 5.5 Service Pack 2 Service is Up"
Should it return
"Windows "
or
"Windows Issue 2 SurfControl Web Filter Version 5.5 Service Pack 2 Service "
Perhaps that will never occur but similar issues might arise.
Probably
Find what: is * (space "is" space "*")
as Don suggests is even more precise
Last edited by Marcol; 01-21-2011 at 08:23 AM.
edit: below composed prior to above edit - relates to the "is *" example:
Even then that approach is not watertight, for example:
The Evaluate route allows OP to append string such that we can reduce risk of false positives"This is great isn't it?"
And fire a LEFT against it based on " is "" This is great isn't it? is "
Though searching for " is *" would resolve the above the Find/Replace would fail should "is" appear as either last or first word in the sentence whereas the Evaluate would succeed*
*assuming you removed case sensitivity via an outer LOWER call - missing in my example!
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Agreed Don, you posted as I was editing to clarify the point.
slightly more robust Evaluate below - added a TRIM & LOWER call
I suspect however that in this instance the Find/Replace will work just fine!.Value = Evaluate("IF(ISTEXT(" & x & "),TRIM(LEFT(" & x & ",FIND("" is "","" ""&LOWER(" & x & ")&"" is "")-1)),REPT(" & x & ",1))")
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
thanks guys. interesting debate going on! love it.......
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks