IS there a macro that can do this? (dave please help)

J

John Kitchens

I am using Excel 2000, and I am having a problem. I can't seem to find a
clear cut answer to my question about something being possible in Excel.

I have a template and on this template is a dropdown that has a list of
names. I can add to this list, and the names are stored in alphabetical
order. This was made through the use of data valadation.

The actual names are hidden on sheet 3. What I would like to be able to do
is create a template that either has these same names in a dropdown that the
user could select OR type a name from the dropdown in a cell and click a
button (or something to that effect) and have excel provide a list of every
xls file that shows that particular name on sheet1 of my template.

I originally tried to just use Windows search but that wouldn't work b/c the
name is stored permenantly on sheet 3 regardless of the name that the user
selects on sheet 1.

I hope that my question makes sense.

Sincerely,
John Kitchens
 
D

Dave Peterson

First,
It's probably better to ask for help without directing it to any specific
person. Many people see the and choose to ignore message--rather than trying to
come up with a solution.

But maybe you could use application.filesearch to find that list of files.

I think that this may work...

Option Explicit
Sub testme()

Dim myCell As Range
Dim rptWks As Worksheet
Dim oRow As Long

Set myCell = ActiveSheet.Range("a1")

If myCell.Value = "" Then
MsgBox "nothing in A1"
Exit Sub
End If

With Application.FileSearch
.NewSearch
'Change this to your directory
.LookIn = "C:\my documents\excel"
.Filename = "*" & myCell.Value & "*.xls"
.SearchSubFolders = True
If .Execute() > 0 Then
Set rptWks = Worksheets.Add
For oRow = 1 To .FoundFiles.Count
rptWks.Cells(oRow, "A").Value = .FoundFiles(oRow)
Next oRow
End If
End With

End Sub

But every .xls file that contains that name needs to have a limit. Can you
search a particular folder? Do you have to search subfolders?
 
D

Dave Peterson

Darn interruptions...

Many people see the name and choose to ignore the message--rather than trying to
come up with a solution.

(just to make it closer to English.)
 
J

John Kitchens

Dave,

I understand about posting a request for a particular person. Point taken!

I still need some help. I think I have a two fold problem. This macro
works, but what I need is to have a way that the user can type a name in the
A1 cell. THIS needs to be a name that is not a filename:
(all files are saved this way: "t1059(101904),
t1060(101904), continuing on until tommorrow, t1124(102004).)

This is my complete path:
C\My Documents\Recycling Solutions Weight Form\Inbound Scrap Form\October
2004\101904

Tommorrow the path for the current's day's files will be the same as above
except it will read "102004".

Now to my problem. On my template the user selects a customer's name from a
combobox.

Problem 1: Can there be a way that when the user selects the customer's
name from the combox that the selected name will also appear in cell G6 on
sheet 1?

Problem2: If we can get the selected name to appear on cell G6 on sheet 1,
can we then have a macro (like the one you submitted) so that in cell A1 of
sheet 1 the user could type the name of the customer and it look through all
of the closed files preferrebly in ALL folders in the following path:
C\My Documents\Recycling Solutions Weight Form\Inbound Scrap Form\

For example the customer "Thermo King"

If I could go to cell A1 (on your new macro sheet) and type in Thermo King
it would be able to look at all of the closed files and then provide me with
a list of every file that contains Thermo King on cell G6 Sheet 1 of all of
my individual files.

If I could have that I would be set.

I know that I am asking a lot, but I just can't figure this out on my own.

Any help that you, OR ANYONE, can give will be greatly appreciated.

Sincerely,

John Kitchens
 
D

Dave Peterson

Interspersed...



John said:
Dave,

I understand about posting a request for a particular person. Point taken!

I still need some help. I think I have a two fold problem. This macro
works, but what I need is to have a way that the user can type a name in the
A1 cell. THIS needs to be a name that is not a filename:
(all files are saved this way: "t1059(101904),
t1060(101904), continuing on until tommorrow, t1124(102004).)

This is my complete path:
C\My Documents\Recycling Solutions Weight Form\Inbound Scrap Form\October
2004\101904

Tommorrow the path for the current's day's files will be the same as above
except it will read "102004".

Now to my problem. On my template the user selects a customer's name from a
combobox.

Problem 1: Can there be a way that when the user selects the customer's
name from the combox that the selected name will also appear in cell G6 on
sheet 1?

If you used a combobox from the control toolbox toolbar, you can just use the
linked cell.

If you used a dropdown from the Forms toolbar, you could use the linked cell and
a formula:

with A1 as the linked cell and B1:b10 the list.
=if(a1="","",index(b1:b10,a1))


Problem2: If we can get the selected name to appear on cell G6 on sheet 1,
can we then have a macro (like the one you submitted) so that in cell A1 of
sheet 1 the user could type the name of the customer and it look through all
of the closed files preferrebly in ALL folders in the following path:
C\My Documents\Recycling Solutions Weight Form\Inbound Scrap Form\

For example the customer "Thermo King"

So you type in a value that's in G6 of Sheet1 that maybe in a workbook in that
folder?

You could use the .filesearch to get that list with a change to the code

..Filename = "*" & myCell.Value & "*.xls"
becomes:
..Filename = ".xls"

After you have the list, you have at least two choices.

Open each workbook and examine the value in that cell.
Or use a you can use a techniques at John Walkenbach's site:
http://j-walk.com/ss/excel/eee/eee009.txt


If I could go to cell A1 (on your new macro sheet) and type in Thermo King
it would be able to look at all of the closed files and then provide me with
a list of every file that contains Thermo King on cell G6 Sheet 1 of all of
my individual files.

Maybe something like:

Option Explicit
Sub testme02()

Dim myFiles() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim myCell As Range
Dim rptWks As Worksheet
Dim oRow As Long

Set myCell = ActiveSheet.Range("a1")

If myCell.Value = "" Then
MsgBox "nothing in A1"
Exit Sub
End If

'change to point at the folder to check
myPath = "c:\my documents\excel"
If Right(myPath, 1) <> "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile <> ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop

oRow = 1
If fCtr > 0 Then
Set rptWks = Worksheets.Add
For fCtr = LBound(myFiles) To UBound(myFiles)
If LCase(GetValue(myPath, myFiles(fCtr), "sheet1", "G6")) _
= LCase(myCell.Value) Then
rptWks.Cells(oRow, "A").Value = myPath & myFiles(fCtr)
oRow = oRow + 1
End If
Next fCtr
End If

End Sub
Private Function GetValue(path, file, sheet, range_ref)

'from John Walkenbach's site:
'http://j-walk.com/ss/excel/eee/eee009.txt
'Look for either: GetDataFromClosedFile or GetValue.
'Retrieves a value from a closed workbook

Dim arg As String

'Make sure the file exists
If Right(path, 1) <> "\" Then path = path & "\"

If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If

'Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(range_ref).Range("A1").Address(, , xlR1C1)

'Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)

End Function
 

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