Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I wish to search for 2 separate strings in one file. I prefer to not follow
this sequence: (1) Open txt file (2) search for first string (3) output result (4) close txt file (5) repeat 1-4 for second string. I would like to perform the query without having to close and reopen the txt file. My current program resembles what it listed below. Obviously my syntax for "LineofText2" is incorrect, so please offer your suggestions. Is possible to do something along the lines of "Open fName For Input As #1 and #2"? thanks in advance. Open fName For Input As #1 sStr = "" sStr2 = "" Do While Not EOF(1) Line Input #1, LineofText If (InStr(1, LineofText, "Reboot", vbTextCompare)) Then sStr = Left(LineofText, 12) End If If (InStr(1, LineofText2, "Yes", vbTextCompare)) Then sStr2 = Mid(LineofText2, 12, 3) End If Loop Cells(iVar, "A").Value = sStr Cells(iVar, "B").Value = sStr2 Close #1 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What happens if you just use LineOfText (drop the 2 from the variable name)?
flaterp wrote: I wish to search for 2 separate strings in one file. I prefer to not follow this sequence: (1) Open txt file (2) search for first string (3) output result (4) close txt file (5) repeat 1-4 for second string. I would like to perform the query without having to close and reopen the txt file. My current program resembles what it listed below. Obviously my syntax for "LineofText2" is incorrect, so please offer your suggestions. Is possible to do something along the lines of "Open fName For Input As #1 and #2"? thanks in advance. Open fName For Input As #1 sStr = "" sStr2 = "" Do While Not EOF(1) Line Input #1, LineofText If (InStr(1, LineofText, "Reboot", vbTextCompare)) Then sStr = Left(LineofText, 12) End If If (InStr(1, LineofText2, "Yes", vbTextCompare)) Then sStr2 = Mid(LineofText2, 12, 3) End If Loop Cells(iVar, "A").Value = sStr Cells(iVar, "B").Value = sStr2 Close #1 -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
" Run time error 55. File already open."
"Dave Peterson" wrote: What happens if you just use LineOfText (drop the 2 from the variable name)? flaterp wrote: I wish to search for 2 separate strings in one file. I prefer to not follow this sequence: (1) Open txt file (2) search for first string (3) output result (4) close txt file (5) repeat 1-4 for second string. I would like to perform the query without having to close and reopen the txt file. My current program resembles what it listed below. Obviously my syntax for "LineofText2" is incorrect, so please offer your suggestions. Is possible to do something along the lines of "Open fName For Input As #1 and #2"? thanks in advance. Open fName For Input As #1 sStr = "" sStr2 = "" Do While Not EOF(1) Line Input #1, LineofText If (InStr(1, LineofText, "Reboot", vbTextCompare)) Then sStr = Left(LineofText, 12) End If If (InStr(1, LineofText2, "Yes", vbTextCompare)) Then sStr2 = Mid(LineofText2, 12, 3) End If Loop Cells(iVar, "A").Value = sStr Cells(iVar, "B").Value = sStr2 Close #1 -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ignore the error. I overlooked one of my "LineofText2". It works.
"flaterp" wrote: " Run time error 55. File already open." "Dave Peterson" wrote: What happens if you just use LineOfText (drop the 2 from the variable name)? flaterp wrote: I wish to search for 2 separate strings in one file. I prefer to not follow this sequence: (1) Open txt file (2) search for first string (3) output result (4) close txt file (5) repeat 1-4 for second string. I would like to perform the query without having to close and reopen the txt file. My current program resembles what it listed below. Obviously my syntax for "LineofText2" is incorrect, so please offer your suggestions. Is possible to do something along the lines of "Open fName For Input As #1 and #2"? thanks in advance. Open fName For Input As #1 sStr = "" sStr2 = "" Do While Not EOF(1) Line Input #1, LineofText If (InStr(1, LineofText, "Reboot", vbTextCompare)) Then sStr = Left(LineofText, 12) End If If (InStr(1, LineofText2, "Yes", vbTextCompare)) Then sStr2 = Mid(LineofText2, 12, 3) End If Loop Cells(iVar, "A").Value = sStr Cells(iVar, "B").Value = sStr2 Close #1 -- Dave Peterson |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Simply search the same string twice:
Sub TryNow() Dim fName As String Dim LineofText As String Dim sStr As String Dim sStr2 As String Dim iVar As Long Dim Changed As Boolean fName = "Whatever.prn" Open fName For Input As #1 sStr = "" sStr2 = "" iVar = 1 Do While Not EOF(1) Line Input #1, LineofText Changed = False If InStr(1, LineofText, "Reboot", vbTextCompare) 0 Then sStr = Left(LineofText, 12) Cells(iVar, "A").Value = sStr Changed = True End If If InStr(1, LineofText, "Yes", vbTextCompare) 0 Then sStr2 = Mid(LineofText, 12, 3) Cells(iVar, "B").Value = sStr2 Changed = True End If If Changed Then iVar = iVar + 1 Loop Close #1 End Sub -- HTH, Bernie MS Excel MVP "flaterp" wrote in message ... I wish to search for 2 separate strings in one file. I prefer to not follow this sequence: (1) Open txt file (2) search for first string (3) output result (4) close txt file (5) repeat 1-4 for second string. I would like to perform the query without having to close and reopen the txt file. My current program resembles what it listed below. Obviously my syntax for "LineofText2" is incorrect, so please offer your suggestions. Is possible to do something along the lines of "Open fName For Input As #1 and #2"? thanks in advance. Open fName For Input As #1 sStr = "" sStr2 = "" Do While Not EOF(1) Line Input #1, LineofText If (InStr(1, LineofText, "Reboot", vbTextCompare)) Then sStr = Left(LineofText, 12) End If If (InStr(1, LineofText2, "Yes", vbTextCompare)) Then sStr2 = Mid(LineofText2, 12, 3) End If Loop Cells(iVar, "A").Value = sStr Cells(iVar, "B").Value = sStr2 Close #1 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
search for multiple strings | Excel Discussion (Misc queries) | |||
How do I filter or search mulitple for text strings? | Excel Discussion (Misc queries) | |||
Search for multiple strings in a list (w/in 1 cell) w/ Advanced fi | Excel Discussion (Misc queries) | |||
Search multiple strings in each cell | Excel Programming | |||
Search multiple strings Difficult to figure out | Excel Programming |