Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default text in file



Oops, sorry. I needed to mention that the file being searched is a
simple text file.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to tell number of spaces between values in saved text file fromthe original xls file [email protected] Excel Discussion (Misc queries) 1 January 15th 08 11:52 AM
Saving multi-tab excel file created from comma delimited text file Marcus Aurelius Excel Programming 2 December 19th 05 05:16 PM
How do I import text file, analyze data, export results, open next file Geoffro Excel Programming 2 March 6th 05 08:02 PM
Excel VBA - open text file, replace text, save file? Cybert Excel Programming 2 October 2nd 04 01:05 AM
importing text file, removing data and outputting new text file Pal Excel Programming 8 February 27th 04 08:32 PM


All times are GMT +1. The time now is 04:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"