FalconBLUE
New Member
- Joined
- Jan 3, 2008
- Messages
- 11
Hi everybody,
I'm working on a project and came across a problem. I hope you have the solution. I want to find a selected person name and surname by textbox on a userform in closed workbook sheets. This workbook has 21 sub sheets. Actually, I wrote a code as below but didn't work. I think it should work but not. Where am I making mistake?
I'm working on a project and came across a problem. I hope you have the solution. I want to find a selected person name and surname by textbox on a userform in closed workbook sheets. This workbook has 21 sub sheets. Actually, I wrote a code as below but didn't work. I think it should work but not. Where am I making mistake?
Code:
Sub AracListSIL()
Dim ArList As New Excel.Application
Dim nwb As New Excel.Workbook
Dim ws As Worksheet
Dim rFound As Range
Dim strName As String
Set nwb = ArList.Workbooks.Open("D:\Mega\Projects\ProjeMac\F iles\Arac_Listeleri.xlsx")
On Error Resume Next
strName = USERPERSONEL.txtAdSoyad 'adsoyad=name surname in textbox on userform
If strName = "" Then Exit Sub
For Each ws In ArList.Worksheets
With ws.UsedRange
For i = 1 To 60
Set rFound = ws.UsedRange.Find(what:=strName, After:=.Range("C" & i), SearchDirection:=xlNext, lookAt:=xlWhole)
If Not rFound Is Nothing Then
Application.Goto rFound, True
Exit Sub
End If
Next i
End With
Next ws
On Error GoTo 0
MsgBox "Value not found"
nwb.Save
nwb.Close
Set ArList = Nothing
Set nwb = Nothing
End Sub