View Single Post
  #2   Report Post  
SquareMeal SquareMeal is offline
Junior Member
 
Posts: 3
Default

Quote:
Originally Posted by leonakos View Post
I want to open a txt file on a worksheet and then to search for two words inside the worksheet and when it finds one of the two strings to do something

can anyone help ??
You can write Visual Basic code to open and read a text file, etc... but I'm assuming you want a simple answer:

(this example pertains to Excel 2007 -- there may be differences for other versions of Excel)

Open a blank worksheet.
Click on the "Data" tab (near the top of the window).
Click on "From Text"
A Security Notice window might pop up, if so, click "OK"
A window opens asking for "File Name" -- navigate through the folders until you find the text file you want to read.
Click once on the "Filename" then click "Import"
The Text Import Wizard window opens to guide you through the import of text data into your worksheet.
Assuming your file is delimited by some character (commas, tabs, semicolons, etc.), select the radio button for "Delimited" then click "Next".
Check the boxes which correspond to the type of delimiters contained within the file. As you check these boxes, you will see a sample of the data divided into fields to show you how the text is going to be broken up upon import.
Click "Next" with the sample divisions look right (you have selected the appropriate delimiters for that file).
The next screen lets you click on each column to then specify if it is General, Text, a Date, or a field you do not want to import.
Click "Finish"
The next window asks where to put the data. Enter "=$A$1" (without the quote marks) to have the text start in the upper left corner of the worksheet.
Click "OK"
Now you should be looking at the worksheet with the text data you just imported.

To answer the second part of your question (how to find two particular words inside the text), I'll need more information:

Are these two searches where you will find two separate words, or are the words together (with a space between) and you want a single search for the pair?

Are you searching for a word that might be imbedded within the string which makes up one field? For example, you might be looking for "cat" in the following table of text:

animalsatthezoo
horsedogmonkey
zebracatsnake
birdfish

"cat" could be identified to be contained within the 3rd element of the table.

Please provide a sample of text, which part of the text you are looking for, and what you want to do when you find the word you are looking for.