#1   Report Post  
Posted to microsoft.public.excel.misc
SJ SJ is offline
external usenet poster
 
Posts: 22
Default Folder search

At present to search for a date within my workbook I use the following code,

Sub myfind()
Dim Message, Title, Default, SearchString
Message = "Enter date as ( d-* or dd-* )" ' Set prompt.
Title = "Select Day " ' Set title.
Default = "dd-mmm-yy" ' Set default.
' Display message, title, and default value.
SearchString = InputBox(Message, Title, Default)

'SearchString = "Rob"
Set S = Sheets.Application
For Each S In Application.Sheets

With S.Range("A1:IV65536")
Set F = .find(SearchString, MatchCase:=False, LookAt:=xlPart,
LookIn:=xlValues)
If F Is Nothing Then
Else
Location = F.Address
S.Select
Range(Location).Select
Exit For
End If
End With
Next S
End Sub


What I want to do is to be able to apply this to searching a folder and it's
subfolders for a date within the books in the folders. The date I will be
searching for will only ever exist once in the folders. Is there a way I can
search the folders for a date that exists in a cell on each spreadsheet
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Folder search

Change the variable Folder as required

Sub myfind()
Dim Message, Title, Default, SearchString

'define folder, make sure slash is last character
Folder = "c:\temp\"

Message = "Enter date as ( d-* or dd-* )" ' Set prompt.
Title = "Select Day " ' Set title.
Default = "dd-mmm-yy" ' Set default.
' Display message, title, and default value.
SearchString = InputBox(Message, Title, Default)

FName = Dir(Folder & "*.xls")
Do While FName < ""
Set bk = Workbooks.Open(Filename:=Folder & FName)

Found = False
For Each S In bk.Sheets

With S.Range("A1:IV65536")
Set F = .Find(SearchString, MatchCase:=False, _
LookAt:=xlPart, LookIn:=xlValues)
If Not F Is Nothing Then

Location = F.Address
S.Range(Location).Select
Found = True
Exit For
End If
End With
Next S
If Found = False Then
bk.Close savechanges:=False
Else
Exit Do
End If
Loop
End Sub


"Sj" wrote:

At present to search for a date within my workbook I use the following code,

Sub myfind()
Dim Message, Title, Default, SearchString
Message = "Enter date as ( d-* or dd-* )" ' Set prompt.
Title = "Select Day " ' Set title.
Default = "dd-mmm-yy" ' Set default.
' Display message, title, and default value.
SearchString = InputBox(Message, Title, Default)

'SearchString = "Rob"
Set S = Sheets.Application
For Each S In Application.Sheets

With S.Range("A1:IV65536")
Set F = .find(SearchString, MatchCase:=False, LookAt:=xlPart,
LookIn:=xlValues)
If F Is Nothing Then
Else
Location = F.Address
S.Select
Range(Location).Select
Exit For
End If
End With
Next S
End Sub


What I want to do is to be able to apply this to searching a folder and it's
subfolders for a date within the books in the folders. The date I will be
searching for will only ever exist once in the folders. Is there a way I can
search the folders for a date that exists in a cell on each spreadsheet

  #3   Report Post  
Posted to microsoft.public.excel.misc
SJ SJ is offline
external usenet poster
 
Posts: 22
Default Folder search

Joel

I tried this but this opens the excel book in the folder and not the one
where the date is, the main folder is called Balance and within this is a
Master excel book and two subfolders called 2009 & 2010, within these folders
are workbooks for each month of the year, whay I need to do is be able to
type in the date and workbook that contains that date opens to that sheet
then I can copy the information I need from there.

"Joel" wrote:

Change the variable Folder as required

Sub myfind()
Dim Message, Title, Default, SearchString

'define folder, make sure slash is last character
Folder = "c:\temp\"

Message = "Enter date as ( d-* or dd-* )" ' Set prompt.
Title = "Select Day " ' Set title.
Default = "dd-mmm-yy" ' Set default.
' Display message, title, and default value.
SearchString = InputBox(Message, Title, Default)

FName = Dir(Folder & "*.xls")
Do While FName < ""
Set bk = Workbooks.Open(Filename:=Folder & FName)

Found = False
For Each S In bk.Sheets

With S.Range("A1:IV65536")
Set F = .Find(SearchString, MatchCase:=False, _
LookAt:=xlPart, LookIn:=xlValues)
If Not F Is Nothing Then

Location = F.Address
S.Range(Location).Select
Found = True
Exit For
End If
End With
Next S
If Found = False Then
bk.Close savechanges:=False
Else
Exit Do
End If
Loop
End Sub


"Sj" wrote:

At present to search for a date within my workbook I use the following code,

Sub myfind()
Dim Message, Title, Default, SearchString
Message = "Enter date as ( d-* or dd-* )" ' Set prompt.
Title = "Select Day " ' Set title.
Default = "dd-mmm-yy" ' Set default.
' Display message, title, and default value.
SearchString = InputBox(Message, Title, Default)

'SearchString = "Rob"
Set S = Sheets.Application
For Each S In Application.Sheets

With S.Range("A1:IV65536")
Set F = .find(SearchString, MatchCase:=False, LookAt:=xlPart,
LookIn:=xlValues)
If F Is Nothing Then
Else
Location = F.Address
S.Select
Range(Location).Select
Exit For
End If
End With
Next S
End Sub


What I want to do is to be able to apply this to searching a folder and it's
subfolders for a date within the books in the folders. The date I will be
searching for will only ever exist once in the folders. Is there a way I can
search the folders for a date that exists in a cell on each spreadsheet

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Folder search

I extracted the year from the data put into the input box and then search the
correct folder

Sub myfind()
Dim Message, Title, Default, SearchString

'define folder, make sure slash is last character
Folder = "c:\temp\"

Message = "Enter date as ( d-* or dd-* )" ' Set prompt.
Title = "Select Day " ' Set title.
Default = "dd-mmm-yy" ' Set default.
' Display message, title, and default value.
SearchString = Trim(InputBox(Message, Title, Default))

'get year
Sdate = DateValue(SearchString)

FName = Dir(Folder & Year(Sdate) & "\*.xls")
Do While FName < ""
Set bk = Workbooks.Open(Filename:=Folder & FName)

Found = False
For Each S In bk.Sheets

With S.Range("A1:IV65536")
Set F = .Find(SearchString, MatchCase:=False, _
LookAt:=xlPart, LookIn:=xlValues)
If Not F Is Nothing Then

Location = F.Address
S.Range(Location).Select
Found = True
Exit For
End If
End With
Next S
If Found = False Then
bk.Close savechanges:=False
Else
Exit Do
End If
Loop
End Sub



"Sj" wrote:

Joel

I tried this but this opens the excel book in the folder and not the one
where the date is, the main folder is called Balance and within this is a
Master excel book and two subfolders called 2009 & 2010, within these folders
are workbooks for each month of the year, whay I need to do is be able to
type in the date and workbook that contains that date opens to that sheet
then I can copy the information I need from there.

"Joel" wrote:

Change the variable Folder as required

Sub myfind()
Dim Message, Title, Default, SearchString

'define folder, make sure slash is last character
Folder = "c:\temp\"

Message = "Enter date as ( d-* or dd-* )" ' Set prompt.
Title = "Select Day " ' Set title.
Default = "dd-mmm-yy" ' Set default.
' Display message, title, and default value.
SearchString = InputBox(Message, Title, Default)

FName = Dir(Folder & "*.xls")
Do While FName < ""
Set bk = Workbooks.Open(Filename:=Folder & FName)

Found = False
For Each S In bk.Sheets

With S.Range("A1:IV65536")
Set F = .Find(SearchString, MatchCase:=False, _
LookAt:=xlPart, LookIn:=xlValues)
If Not F Is Nothing Then

Location = F.Address
S.Range(Location).Select
Found = True
Exit For
End If
End With
Next S
If Found = False Then
bk.Close savechanges:=False
Else
Exit Do
End If
Loop
End Sub


"Sj" wrote:

At present to search for a date within my workbook I use the following code,

Sub myfind()
Dim Message, Title, Default, SearchString
Message = "Enter date as ( d-* or dd-* )" ' Set prompt.
Title = "Select Day " ' Set title.
Default = "dd-mmm-yy" ' Set default.
' Display message, title, and default value.
SearchString = InputBox(Message, Title, Default)

'SearchString = "Rob"
Set S = Sheets.Application
For Each S In Application.Sheets

With S.Range("A1:IV65536")
Set F = .find(SearchString, MatchCase:=False, LookAt:=xlPart,
LookIn:=xlValues)
If F Is Nothing Then
Else
Location = F.Address
S.Select
Range(Location).Select
Exit For
End If
End With
Next S
End Sub


What I want to do is to be able to apply this to searching a folder and it's
subfolders for a date within the books in the folders. The date I will be
searching for will only ever exist once in the folders. Is there a way I can
search the folders for a date that exists in a cell on each spreadsheet

  #5   Report Post  
Posted to microsoft.public.excel.misc
SJ SJ is offline
external usenet poster
 
Posts: 22
Default Folder search

When I tried this one I got an error message saying run-time error 1004
and it seems to be at the point where it says

Set bk = Workbooks.Open(Filename:=Folder & fname)

Any ideas why this would be?
SJ



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Folder search

from
Set bk = Workbooks.Open(Filename:=Folder & FName)

to
Set bk = Workbooks.Open(Filename:=Folder & Year(Sdate) & "\" & FName)
Loop

"Sj" wrote:

When I tried this one I got an error message saying run-time error 1004
and it seems to be at the point where it says

Set bk = Workbooks.Open(Filename:=Folder & fname)

Any ideas why this would be?
SJ

  #7   Report Post  
Posted to microsoft.public.excel.misc
SJ SJ is offline
external usenet poster
 
Posts: 22
Default Folder search

ok, I've done this and when I run it it opens the dialog box to input the
date so I tried 01/09/2009 and the excel sheet that opened was the November
workbook and not the one titled September would this have anything to with
the date is formatted?

"Joel" wrote:

from
Set bk = Workbooks.Open(Filename:=Folder & FName)

to
Set bk = Workbooks.Open(Filename:=Folder & Year(Sdate) & "\" & FName)
Loop

"Sj" wrote:

When I tried this one I got an error message saying run-time error 1004
and it seems to be at the point where it says

Set bk = Workbooks.Open(Filename:=Folder & fname)

Any ideas why this would be?
SJ

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Folder search

Your original requst said :

"What I want to do is to be able to apply this to searching a folder and
it's
subfolders for a date within the books in the folders."

You said within the BOOKS. So my code is searcing all the files in the
folder for the year specified by the Input box. The code is leaving open the
first file it finds with the date you specified in the 1st worksheets sheet
with that date. The code is using DIR() which randomly selects all the files
specified which in this case is "*.xls". then it goes through the sheets in
the order they are listed in the workbokk from left to right.

I'm not sure if the problem is with the date format since I don't know whatt
data is actually stopped on and the date you specified in the inputbox. If
you want to find the earliest or lastest worksheet with the data you are
looking for I need you to specify a different algorithm for which worksheet
you want opened.

"Sj" wrote:

ok, I've done this and when I run it it opens the dialog box to input the
date so I tried 01/09/2009 and the excel sheet that opened was the November
workbook and not the one titled September would this have anything to with
the date is formatted?

"Joel" wrote:

from
Set bk = Workbooks.Open(Filename:=Folder & FName)

to
Set bk = Workbooks.Open(Filename:=Folder & Year(Sdate) & "\" & FName)
Loop

"Sj" wrote:

When I tried this one I got an error message saying run-time error 1004
and it seems to be at the point where it says

Set bk = Workbooks.Open(Filename:=Folder & fname)

Any ideas why this would be?
SJ

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
search a folder? JCW New Users to Excel 2 July 8th 09 07:26 PM
Microsoft Search opens when I click on a file folder tedster Setting up and Configuration of Excel 1 December 10th 08 06:20 PM
search folder/directory for a phrase inside excel files pwrichcreek Excel Discussion (Misc queries) 5 August 11th 08 09:39 PM
Can Excel search for workbook data in a Windows folder? B Diggity Excel Discussion (Misc queries) 1 October 25th 07 10:24 PM
Import Folder Search Results in a spreadsheet? Mark B Excel Discussion (Misc queries) 1 April 9th 05 05:17 PM


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

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"