ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   text in file (https://www.excelbanter.com/excel-programming/411257-text-file.html)

codie

text in file
 
I am looking for a fast and efficient method to verify if a text
string exists in a file. Has anyone created anything like this?

The files are typically under 100K but I will be doing thousands of
checks.

GTVT06

text in file
 
You can try this

Sub Test()

Dim i As String
i = InputBox("Find:", "Search For Value")
Cells.Find(What:=i, After:=Range("A1"), LookIn:=xlFormulas, LookAt
_
:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext).Activate
If ActiveCell.Value = i Then MsgBox i & " was found in cell " &
ActiveCell.Address


End Sub

GTVT06

text in file
 
Modified it to search your whole workbook. Ofcourse you can hardcode
the string you would like to search for and remove the input box, and
also modify the way you would like to identify the found results.

Sub Test()
Dim i As String
Dim n As Single

i = InputBox("Find:", "Search For Value")
For n = 1 To Sheets.Count
Sheets(n).Select 'Activate
On Error Resume Next
With cells
.Find(What:=i, After:=Range("A1"), LookIn:=xlFormulas, LookAt
_
:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext).Activate
End With
If ActiveCell.Value = i Then
MsgBox i & " was found in cell " & ActiveCell.Address
Exit Sub
Else
End If
Next n


End Sub

codie

text in file
 


Oops, sorry. I needed to mention that the file being searched is a
simple text file.

Tim Williams

text in file
 
Use native VBA functions or the FileSystemObject to read the file into a
string variable, then use instr() to check for your text.

Tim

"codie" wrote in message
...


Oops, sorry. I needed to mention that the file being searched is a
simple text file.





All times are GMT +1. The time now is 10:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com