![]() |
Edit String Variable "on the fly"?
I am evaluating a relatively large data set by using (among other things)
InStr against a search string variable. Dim strSearchList As String strSearchList = "ROL, REG, OT-, PN2" On each pass through a sub-process where this is used other qualifying factors are evaluated. Once all qualifying factors are met, the "found" item in the string is "used", but must be ignored on subsequent passes through. So, if I process for the "REG" element, what I need to do is re-state strSearchList as "ROL, OT-, PN2" -- that is, with the "REG" removed. So how do I do that? -- Dave Temping with Staffmark in Rock Hill, SC |
Edit String Variable "on the fly"?
How about simpy:
strSearchList = Replace(str, ", REG", "", 1, -1, vbBinaryCompare) RBS "Dave Birley" wrote in message ... I am evaluating a relatively large data set by using (among other things) InStr against a search string variable. Dim strSearchList As String strSearchList = "ROL, REG, OT-, PN2" On each pass through a sub-process where this is used other qualifying factors are evaluated. Once all qualifying factors are met, the "found" item in the string is "used", but must be ignored on subsequent passes through. So, if I process for the "REG" element, what I need to do is re-state strSearchList as "ROL, OT-, PN2" -- that is, with the "REG" removed. So how do I do that? -- Dave Temping with Staffmark in Rock Hill, SC |
Edit String Variable "on the fly"?
Hi Dave,
Possibly try something like: '============= Public Sub Tester() Dim arr As Variant Dim i As Long arr = VBA.Array("ROL", "REG", "OT-", "PN2") For i = LBound(arr) To UBound(arr) If InStr(1,"yourString", arr(i), vbTextCompare) Then 'Your code End If Next i End Sub '<<============= --- Regards, Norman "Dave Birley" wrote in message ... I am evaluating a relatively large data set by using (among other things) InStr against a search string variable. Dim strSearchList As String strSearchList = "ROL, REG, OT-, PN2" On each pass through a sub-process where this is used other qualifying factors are evaluated. Once all qualifying factors are met, the "found" item in the string is "used", but must be ignored on subsequent passes through. So, if I process for the "REG" element, what I need to do is re-state strSearchList as "ROL, OT-, PN2" -- that is, with the "REG" removed. So how do I do that? -- Dave Temping with Staffmark in Rock Hill, SC |
Edit String Variable "on the fly"?
I am evaluating a relatively large data set by using (among other things)
InStr against a search string variable. Dim strSearchList As String strSearchList = "ROL, REG, OT-, PN2" On each pass through a sub-process where this is used other qualifying factors are evaluated. Once all qualifying factors are met, the "found" item in the string is "used", but must be ignored on subsequent passes through. So, if I process for the "REG" element, what I need to do is re-state strSearchList as "ROL, OT-, PN2" -- that is, with the "REG" removed. So how do I do that? You haven't given enough information to decide for sure, but my gut feeling would be to put your search list items in a String array and just run a For-Next loop to process each one. Depending on what you are doing when you find one, you might need an If-Then-ElseIf or Select Case structure to process the additional steps. So I would be thinking something like this... Dim X As Long Dim strSearchList() As String strSearchList = Split("ROL,REG,OT-,PN2", ",") For X = 0 To Ubound(strSearchList) If InStr(MainString, strSearchList(X)) 0 Then ' ' Item at index X was found, do whatever ' End If Next Again, without more information, the above is only a guess. Rick |
Edit String Variable "on the fly"?
Thank you for your reply. It is interesting that you appear to be the only
one of the three respondants who read my full message including .. «using (among other things) InStr against a search string variable.» Therefore I am working with (as you correctly read) a single string, not an array of strings. Had I used an array of strings, the other answers would have had possibilities, but I am using it in a Case of a Select Case construct, and an array or series of strings won't cut it. The Case construct works like this: Select Case True Case InStr(strCodeList, strMyCurrentSearchItem) <yadda, yadda Select End The problem is that on each WS the data is sorted by Newest at the top. The contents of an item for that latest period (say month 9) are **supposed** to contain the contents of that same item for the preceding two periods (8, 7). **However** this is really bad data, and sometimes the items were not carried forward (we're talking data that ends in 2003 Q4), so I have to look for an item in the latest date. If I find it, then I need to stop looking for it, but if I don't find it, I need to look in each of the other periods. If I still don't find it, I go to the next previous WS. Rick Rothstein (MVP - VB) quite reasonably stated that i didn't give enough information, but somehow, despite that lack you nailed the exact answer I was needing. So I thank you, but I also thank Norman and Rick -- the community here has made my transition from 20 years of VFP to about 6 weeks of VBA a relatively painless one <g! -- Dave Temping with Staffmark in Rock Hill, SC "RB Smissaert" wrote: How about simpy: strSearchList = Replace(str, ", REG", "", 1, -1, vbBinaryCompare) RBS "Dave Birley" wrote in message ... I am evaluating a relatively large data set by using (among other things) InStr against a search string variable. Dim strSearchList As String strSearchList = "ROL, REG, OT-, PN2" On each pass through a sub-process where this is used other qualifying factors are evaluated. Once all qualifying factors are met, the "found" item in the string is "used", but must be ignored on subsequent passes through. So, if I process for the "REG" element, what I need to do is re-state strSearchList as "ROL, OT-, PN2" -- that is, with the "REG" removed. So how do I do that? -- Dave Temping with Staffmark in Rock Hill, SC |
Edit String Variable "on the fly"?
OK, thanks. I take it you got it solved then.
RBS "Dave Birley" wrote in message ... Thank you for your reply. It is interesting that you appear to be the only one of the three respondants who read my full message including .. «using (among other things) InStr against a search string variable.» Therefore I am working with (as you correctly read) a single string, not an array of strings. Had I used an array of strings, the other answers would have had possibilities, but I am using it in a Case of a Select Case construct, and an array or series of strings won't cut it. The Case construct works like this: Select Case True Case InStr(strCodeList, strMyCurrentSearchItem) <yadda, yadda Select End The problem is that on each WS the data is sorted by Newest at the top. The contents of an item for that latest period (say month 9) are **supposed** to contain the contents of that same item for the preceding two periods (8, 7). **However** this is really bad data, and sometimes the items were not carried forward (we're talking data that ends in 2003 Q4), so I have to look for an item in the latest date. If I find it, then I need to stop looking for it, but if I don't find it, I need to look in each of the other periods. If I still don't find it, I go to the next previous WS. Rick Rothstein (MVP - VB) quite reasonably stated that i didn't give enough information, but somehow, despite that lack you nailed the exact answer I was needing. So I thank you, but I also thank Norman and Rick -- the community here has made my transition from 20 years of VFP to about 6 weeks of VBA a relatively painless one <g! -- Dave Temping with Staffmark in Rock Hill, SC "RB Smissaert" wrote: How about simpy: strSearchList = Replace(str, ", REG", "", 1, -1, vbBinaryCompare) RBS "Dave Birley" wrote in message ... I am evaluating a relatively large data set by using (among other things) InStr against a search string variable. Dim strSearchList As String strSearchList = "ROL, REG, OT-, PN2" On each pass through a sub-process where this is used other qualifying factors are evaluated. Once all qualifying factors are met, the "found" item in the string is "used", but must be ignored on subsequent passes through. So, if I process for the "REG" element, what I need to do is re-state strSearchList as "ROL, OT-, PN2" -- that is, with the "REG" removed. So how do I do that? -- Dave Temping with Staffmark in Rock Hill, SC |
Edit String Variable "on the fly"?
Worked like a charm!
-- Dave Temping with Staffmark in Rock Hill, SC "RB Smissaert" wrote: OK, thanks. I take it you got it solved then. RBS "Dave Birley" wrote in message ... Thank you for your reply. It is interesting that you appear to be the only one of the three respondants who read my full message including .. «using (among other things) InStr against a search string variable.» Therefore I am working with (as you correctly read) a single string, not an array of strings. Had I used an array of strings, the other answers would have had possibilities, but I am using it in a Case of a Select Case construct, and an array or series of strings won't cut it. The Case construct works like this: Select Case True Case InStr(strCodeList, strMyCurrentSearchItem) <yadda, yadda Select End The problem is that on each WS the data is sorted by Newest at the top. The contents of an item for that latest period (say month 9) are **supposed** to contain the contents of that same item for the preceding two periods (8, 7). **However** this is really bad data, and sometimes the items were not carried forward (we're talking data that ends in 2003 Q4), so I have to look for an item in the latest date. If I find it, then I need to stop looking for it, but if I don't find it, I need to look in each of the other periods. If I still don't find it, I go to the next previous WS. Rick Rothstein (MVP - VB) quite reasonably stated that i didn't give enough information, but somehow, despite that lack you nailed the exact answer I was needing. So I thank you, but I also thank Norman and Rick -- the community here has made my transition from 20 years of VFP to about 6 weeks of VBA a relatively painless one <g! -- Dave Temping with Staffmark in Rock Hill, SC "RB Smissaert" wrote: How about simpy: strSearchList = Replace(str, ", REG", "", 1, -1, vbBinaryCompare) RBS "Dave Birley" wrote in message ... I am evaluating a relatively large data set by using (among other things) InStr against a search string variable. Dim strSearchList As String strSearchList = "ROL, REG, OT-, PN2" On each pass through a sub-process where this is used other qualifying factors are evaluated. Once all qualifying factors are met, the "found" item in the string is "used", but must be ignored on subsequent passes through. So, if I process for the "REG" element, what I need to do is re-state strSearchList as "ROL, OT-, PN2" -- that is, with the "REG" removed. So how do I do that? -- Dave Temping with Staffmark in Rock Hill, SC |
All times are GMT +1. The time now is 05:16 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com