LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
ann ann is offline
external usenet poster
 
Posts: 210
Default Need More Help for Searching Textboxes

I've gotten great help from Tom Ogilvy and K Dales on this already, but I
can't get it to run correctly and really need to get moving on this project.

My current code is listed below. I have an Excel file with 2000+ account
numbers that I am searching for in a folder with Excel workbooks. I get back
a "Yes" if it is found and a "No" if it's not.

It is working great, except some of the files have worksheets with Text
Boxes on them, and the account # has been entered into the text box - and the
macro won't find it there.

Tom suggested that I add this code to the original, but I can't get it into
the correct place to run:

Dim tbox As Textbox

For Each tbox In .sheets(sh).Textboxes
If instr(1,AcNo,tbox.Text,vbTextcompare) Then
' AcNo found

End If
Next


Any help will be greatly appreciated. I have many, many files to search and
unfortunately, there is a bunch of the with the Textboxes.

Original code (runs great, except it misses the textboxes):

Sub FastAcNos()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim tbox As TextBox
Dim AcNo As String
Dim eAc As Long
Dim i As Long
Dim sh As Long
Dim fndAc As Range

On Error Goto Errorhandler

Application.ScreenUpdating = False

eAc = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder("c:\Documents and Settings" & _
"\zzfy98\My Documents\Test") 'change directory

For Each objFile In objFolder.Files

If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path _
& "\" & objFile.Name, UpdateLinks:=False

With Workbooks(objFile.Name)
For sh = 1 To .Sheets.Count
bDone = True

For i = 1 To eAc
If LCase(ThisWorkbook.Sheets("Sheet1") _
.Cells(i, 2).Value) < "yes" Then
' All accounts not found

bDone = False
AcNo = ThisWorkbook.Sheets("Sheet1").Cells(i,
1).Value

With .Sheets(sh).Cells
Set fndAc = .Find(AcNo _
, LookIn:=xlValues _
, Lookat:=xlPart _
, MatchCase:=True)

End With

If Not fndAc Is Nothing Then
ThisWorkbook.Sheets("Sheet1"). _
Cells(i, 2).Value = "Yes"
End If
End If
Next i

If bDone Then
.Close False

Exit Sub
End If
Next sh
.Close False
Set objFile = Nothing
End With
End If
Next

For i = 1 To eAc

With ThisWorkbook.Sheets("sheet1")
If IsEmpty(.Cells(i, 2)) Then
.Cells(i, 2).Value = "No"
End If
End With
Next

Errorhandler:
Application.ScreenUpdating = True
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing

End Sub
 
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
Textboxes SAL Excel Discussion (Misc queries) 2 July 13th 07 12:24 AM
Searching, matching then searching another list based on the match A.S. Excel Discussion (Misc queries) 1 December 13th 06 05:08 AM
Searching Textboxes on worksheets Annie Oakley Excel Programming 1 November 22nd 05 03:55 PM
Textboxes Subs Excel Programming 2 September 28th 05 08:49 PM
searching for a combobox.value and filling in textboxes from results GregJG[_18_] Excel Programming 3 July 8th 04 12:41 PM


All times are GMT +1. The time now is 02:11 AM.

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

About Us

"It's about Microsoft Excel"