Excel VBA- Get user input, search the for match, output to text file

G

gnileo

Dear Board
Hi I am a newbie in VBA for Excel. I was given a programming task by my
lecturer and my head is breaking over this.
I have with me now a server log(.txt file) that is huge (abt 16MB). I
am suppose to search the file based on user's input and output the
result back into a text file.
The server log file contains about 10 fields, saparated by tab. I have
managed to run and record the macro to import the text file into Excel.
Now each field has a column and there are about 60000 rows of data. I
am thinking of using a form with a text field for user to enter the
search criteria/value and a button for them to click to initiate the
search.
My major problem now is I don't know how to collect the user's input
and perform the search nor output the search result back to a new text
file. Please help! My project is going to be due soon. :confused:
Thanks so much!
 
C

Cliff Myers

I made a phone list. I added a userform with a textbox and two command
buttons. One to start the search, the other to cancel. After that I
inserted this code into the start command button click event:
'sets up error handler
On Error GoTo errorhandler
'disable screeen flickering
Application.ScreenUpdating = False
'set up range to search
Range("b1:ag53").Select
'sets the find option to match the userform-textbox to the range
Selection.Find(What:=UserForm1.TextBox1.Text, After:=ActiveCell,
LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
'unloads the search form
Unload UserForm1
'Message Box tells user what the name and phone number is
MsgBox "The phone number for " & ActiveCell & "is " & _
ActiveCell.Offset(1, 0)
Cells(1, 1).Select
Exit Sub
'show message box if match not found
errorhandler:
MsgBox "Name not found! Please check spelling or enter a new " & _
"name.", vbOKOnly, "Name not found"
'load find form for new entry
UserForm1.TextBox1.SetFocus
You will need to change the range to your range and change the message
output to show what you found. The
rest should be okay for you use.
Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top