Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Private Sub CmdSearch_Click()
Dim sh As Worksheet Dim rng As Range, firstAddress As String Dim SearchTxt As String SearchTxt = TxtCaseName.Text If TxtCaseName.Text = "" Then GoTo ErrorHandler End If Set sh = Worksheets("Shelter") Set rng = sh.Cells.Find(What:=SearchTxt, After:=sh.Cells.Range("A1"), _ LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) If Not rng Is Nothing Then firstAddress = rng.Address Do Set rng = sh.Cells.FindNext(rng) FrmSelection.LboxSelect.AddItem (rng) & " " & sh.Name Loop While Not rng Is Nothing And rng.Address < firstAddress End If Set sh = Worksheets("Dependency") Set rng = sh.Cells.Find(What:=SearchTxt, After:=sh.Cells.Range("A1"), _ LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) If Not rng Is Nothing Then firstAddress = rng.Address Do Set rng = sh.Cells.FindNext(rng) FrmSelection.LboxSelect.AddItem (rng) & " " & sh.Name Loop While Not rng Is Nothing And rng.Address < firstAddress End If If TxtCaseName.Text = "" Then GoTo ErrorHandler End If Set sh = Worksheets("TPR") Set rng = sh.Cells.Find(What:=SearchTxt, After:=sh.Cells.Range("A1"), _ LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) If Not rng Is Nothing Then firstAddress = rng.Address Do Set rng = sh.Cells.FindNext(rng) FrmSelection.LboxSelect.AddItem (rng) & " " & sh.Name Loop While Not rng Is Nothing And rng.Address < firstAddress End If If FrmSelection.LboxSelect.ListCount = 1 Then Unload Me FrmSelection.Show Else Unload Me FCreate.Show End If ErrorHandler: MsgBox "Please Type a Name", vbInformation, " No Names found" End Sub Is the SearchCode From FSearch ( userForm1) It Pulls up Another Form ( FormSelect) Wich has LboxSelect( ListBox) Private Sub CmdSelect_Click() Dim r As Range Dim ws As Worksheet Dim SearchTxt As String Dim Row As Integer If Me.LboxSelect.Text = "" Then GoTo ErrorHandler Else Search (LboxSelect.Text) End If ErrorHandler: MsgBox "Please Select One", vbOKOnly, "Error" End Sub Is The Selection Button It calls My Search Function Private Function Search(strToSearch As String) Dim sh As Worksheet Dim rng As Range, firstAddress As String Dim SearchTxt As String SearchTxt = strToSearch For Each sh In ThisWorkbook.Worksheets Set rng = sh.Cells.Find(What:=SearchTxt, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) If Not rng Is Nothing Then GoTo ErrorHandler Else Found End If Next sh ErrorHandler: MsgBox "Error" & strToSearch & "Not Found" End Function and here is where my Issues begin When It calls The Function to Do What i need it to do It wont Activate the Sheet Private Function Found(StrList As String) Dim SearchTxt As String Dim rng As Range Dim sh As Worksheet For Each sh In ThisWorkbook.Worksheets SearchTxt = FrmSelection.LboxSelect.Text If FrmSelection.LboxSelect.Text = "" Then GoTo ErrorHandler2 Else Set rng = sh.Cells.Find(What:=SearchTxt, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) If Not rng Is Nothing Then sh.Activate ' My Code to Enable or Disable Textboxes and to Fill TextBoxes goes Here Else GoTo ErrorHandler2 End If End If Next sh End Sub I am doing this right correct? I mean, This is my First Time ever using Functions and Im still Learning so i really dont know :| |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to load a listbox in a userform? | Excel Discussion (Misc queries) | |||
Listbox selection creates form | Excel Programming | |||
Which User Form Listbox selection just checked? | Excel Programming | |||
Load data into a listbox | Excel Programming | |||
Listbox initialized on workbook load | Excel Programming |