T
Terry K
Hello all,
Thank you for taking the time to look at this for me. I am a little bit
of a rookie at this and trying to learn as I continue.
Here is some code that I am working on and having an extemely hard time
in making it work.
I am having two probelms with it. First if the string that I am looking
for is in a1 it does not seem to find it. Next is the findnext routine,
it generates runtime error 1004 "Unable to get the findnext property of
the range class. I think that I have been matching what I have been
reading on this site?? Something misunderstood?
Any help would be appreciated. tia.
Terry
Sub find_files()
Dim filter As Variant
Dim wbk As Workbook, sh As Worksheet
Dim i As Single, rng As Range
Dim firstcell As String
Dim caption As String
Dim selectedfile As Variant
filter = "Excel files (*.xls), *.xls"
caption = "Select a File"
selectedfile = Application.GetOpenFilename(filter, , caption, _
, True)
Select Case IsArray(selectedfile)
Case True
For i = LBound(selectedfile) To UBound(selectedfile)
Set wbk = Workbooks.Open(selectedfile(i))
For Each sh In wbk.Worksheets
Set rng = Cells.Find(UserForm1.TextBox2.Text, _
LookIn:=xlValues, lookat:=xlWhole,
MatchCase:=False)
rng.Activate
Do
If Not rng Is Nothing Then
firstcell = rng.Address
MsgBox "Found " & UserForm1.TextBox2.Text & " in "
_
& wbk.Name & " on Sheet " & sh.Name & " in cell " &
rng.Address & vbCr & vbLf & "Continue?", vbYesNo, "Found your Text"
End If
Set rng = rng.FindNext(after:=firstcell).Activate
<<<<<<problem here>>>>>>
Loop Until ActiveCell.Address = firstcell
Next sh
wbk.Close (False)
Next i
Case False
MsgBox ("No Files Selected")
End Select
End Sub
Thank you for taking the time to look at this for me. I am a little bit
of a rookie at this and trying to learn as I continue.
Here is some code that I am working on and having an extemely hard time
in making it work.
I am having two probelms with it. First if the string that I am looking
for is in a1 it does not seem to find it. Next is the findnext routine,
it generates runtime error 1004 "Unable to get the findnext property of
the range class. I think that I have been matching what I have been
reading on this site?? Something misunderstood?
Any help would be appreciated. tia.
Terry
Sub find_files()
Dim filter As Variant
Dim wbk As Workbook, sh As Worksheet
Dim i As Single, rng As Range
Dim firstcell As String
Dim caption As String
Dim selectedfile As Variant
filter = "Excel files (*.xls), *.xls"
caption = "Select a File"
selectedfile = Application.GetOpenFilename(filter, , caption, _
, True)
Select Case IsArray(selectedfile)
Case True
For i = LBound(selectedfile) To UBound(selectedfile)
Set wbk = Workbooks.Open(selectedfile(i))
For Each sh In wbk.Worksheets
Set rng = Cells.Find(UserForm1.TextBox2.Text, _
LookIn:=xlValues, lookat:=xlWhole,
MatchCase:=False)
rng.Activate
Do
If Not rng Is Nothing Then
firstcell = rng.Address
MsgBox "Found " & UserForm1.TextBox2.Text & " in "
_
& wbk.Name & " on Sheet " & sh.Name & " in cell " &
rng.Address & vbCr & vbLf & "Continue?", vbYesNo, "Found your Text"
End If
Set rng = rng.FindNext(after:=firstcell).Activate
<<<<<<problem here>>>>>>
Loop Until ActiveCell.Address = firstcell
Next sh
wbk.Close (False)
Next i
Case False
MsgBox ("No Files Selected")
End Select
End Sub